#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 2e3 + 5;
int a[MAX_N];
set<int> s;
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; (i) < (n); ++i) scanf("%d", &a[i]);
  int it = -1;
  for (int i = (n)-1; (i) >= 0; --i) {
    if (s.count(a[i])) {
      it = i;
      break;
    }
    s.insert(a[i]);
  }
  if (it == -1) {
    printf("%d\n", 0);
    return 0;
  }
  int ans = it + 1;
  for (int i = 0; (i) < (n); ++i) {
    bool ok = 1;
    while (s.count(a[i])) {
      it++;
      if (it >= n) {
        ok = 0;
        break;
      } else
        s.erase(a[it]);
    }
    if (!ok) break;
    ans = min(ans, it - i);
    s.insert(a[i]);
  }
  printf("%d\n", ans);
  return 0;
}
