#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[n];
  unordered_map<int, int> m;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    m[a[i]]++;
  }
  for (auto &x : m) x.second--;
  for (int i = 0; i < n; i++)
    if (m[a[i]] == 0) m.erase(a[i]);
  if (m.size() == 0)
    cout << 0;
  else {
    int res = INT_MAX;
    for (int i = 0; i < n; i++) {
      unordered_map<int, int> u;
      for (auto x : m) u[x.first] = x.second;
      for (int j = i; j < n; j++) {
        {
          u[a[j]]--;
          if (u[a[j]] <= 0) {
            u.erase(a[j]);
          }
        }
        if (u.size() == 0) {
          res = min(res, j - i + 1);
          break;
        }
      }
    }
    cout << (res == INT_MAX ? 0 : res);
  }
  return 0;
}
