#include <bits/stdc++.h>
using namespace std;
long n, res;
long a[2001];
unordered_map<long, long> f;
bool thu(long k) {
  long i, j, res;
  for (long i = 1; i <= n; i++) f[a[i]] = 0;
  for (long i = 1; i <= n; i++) f[a[i]]++;
  for (long i = 1; i <= k; i++) {
    f[a[i]]--;
  }
  i = 1;
  j = i + k - 1;
  while (i <= n - k + 1) {
    res = 0;
    for (long t = 1; t <= n; t++) {
      if (t < i || t > j) {
        if (f[a[t]] > 1)
          break;
        else
          res++;
      }
    }
    if (res == n - k) return 1;
    f[a[i]]++;
    i++;
    j = i + k - 1;
    f[a[j]]--;
  }
  return 0;
}
void chat() {
  long dau = 0;
  long cuoi = n;
  while (dau <= cuoi) {
    long mid = (dau + cuoi) / 2;
    if (thu(mid)) {
      res = mid;
      cuoi = mid - 1;
    } else
      dau = mid + 1;
  }
  cout << res;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (long i = 1; i <= n; i++) {
    cin >> a[i];
  }
  chat();
  return 0;
}
