#include <bits/stdc++.h>
using namespace std;
map<int, int> mp, mp2;
int n, a[2009];
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  int ans = n;
  for (int l = 1; l <= n; l++)
    if (mp[a[l]] <= 1) {
      int r = n;
      mp2.clear();
      while (l <= r && !mp[a[r]] && !mp2[a[r]]) mp2[a[r]] = 1, r--;
      ans = min(ans, r - l + 1);
      mp[a[l]]++;
      if (mp[a[l]] == 2) break;
    }
  cout << ans << endl;
  return 0;
}
