#include <bits/stdc++.h>
using namespace std;
const int N = 2e6 + 100;
template <class nmsl>
inline void read(nmsl &x) {
  x = 0;
  char ch = getchar(), w = 0;
  while (!isdigit(ch)) w = (ch == '-'), ch = getchar();
  while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
  x = w ? -x : x;
}
map<int, int> mp;
int val[N], n, sum[2010], pol;
int ans = 2e9;
int s[2010][2010];
inline int check(int x) {
  for (register int i = 1; i <= n; i++) {
    for (register int j = i; j <= i + x - 1; j++) {
      sum[mp[val[j]]]--;
    }
    int flag = 0;
    for (register int j = 1; j <= pol; j++) {
      if (sum[j] > 1) {
        flag = 1;
        break;
      }
    }
    for (register int j = i; j <= i + x - 1; j++) {
      sum[mp[val[j]]]++;
    }
    if (!flag) return 1;
  }
  return 0;
}
int main() {
  read(n);
  for (register int i = 1; i <= n; i++) {
    read(val[i]);
    if (!mp[val[i]]) mp[val[i]] = ++pol;
    sum[mp[val[i]]]++;
    for (register int j = 1; j <= pol; j++) s[i][j] = sum[j];
  }
  int l = 0, r = n;
  while (l < r) {
    int mid = (l + r) >> 1;
    if (check(mid))
      r = mid;
    else
      l = mid + 1;
  }
  cout << r;
  return 0;
}
