#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int MAX_N = 2000 + 5;
int n;
int a[MAX_N];
void solve() {
  map<int, int> mp;
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (++mp[a[i]] == 2) ans++;
  }
  int s = 0, t = 0;
  int res = INF;
  while (s < n) {
    while (t < n && ans != 0) {
      if (--mp[a[t++]] == 1) ans--;
    }
    if (ans == 0)
      res = min(res, t - s);
    else
      break;
    if (++mp[a[s++]] == 2) ans++;
  }
  printf("%d\n", res);
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", a + i);
  solve();
  return 0;
}
