#include <bits/stdc++.h>
using namespace std;
int a[2005];
int main() {
  int n;
  cin >> n;
  set<int> has;
  int l, r;
  for (int i = 1; i <= n; ++i) cin >> a[i];
  for (int i = n; i >= 1; --i) {
    if (has.count(a[i])) break;
    has.insert(a[i]);
    r = i;
  }
  int ans = n;
  for (int l = 1; l <= n; ++l) {
    ans = min(ans, r - l);
    while (r <= n && has.count(a[l])) {
      has.erase(a[r++]);
    }
    if (has.count(a[l])) break;
    has.insert(a[l]);
  }
  cout << ans << endl;
}
