#include <bits/stdc++.h>
using namespace std;
const int maxn = 2000 + 5;
int a[maxn];
int main() {
  int n;
  map<int, int> have, need;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    if (have[a[i]] == 0)
      have[a[i]] = 1;
    else
      need[a[i]]++;
  }
  if (!need.size())
    cout << 0 << endl;
  else {
    int res = maxn, s = 0, t = 0, cnt = 0;
    have.clear();
    while (1) {
      while (cnt != need.size() && t < n) {
        have[a[++t]]++;
        if (need.count(a[t]) && need[a[t]] == have[a[t]]) cnt++;
      }
      if (cnt != need.size()) break;
      res = min(res, t - s);
      have[a[++s]]--;
      if (need.count(a[s]) && have[a[s]] == need[a[s]] - 1) cnt--;
    }
    cout << res << endl;
  }
  return 0;
}
