#include <bits/stdc++.h>
using namespace std;
const int MN = 2e3 + 5;
const int P = 1e3;
int n;
int a[MN];
int ans = 1 << 20;
int main(int argc, char** argv) {
  int n;
  scanf("%d", &n);
  ans = n - 1;
  for (int i = 1; i <= n; ++i) scanf("%d", a + i);
  for (int l = 0; l <= n; ++l) {
    map<int, bool> m;
    bool can = 1;
    for (int i = 1; i <= l; ++i)
      if (m[a[i]]) {
        can = 0;
        break;
      } else
        m[a[i]] = 1;
    if (!can) continue;
    ans = min(n - l, ans);
    for (int r = n; r > l; --r)
      if (m[a[r]])
        break;
      else
        m[a[r]] = 1, ans = min(r - 1 - l, ans);
  }
  printf("%d", ans);
  return 0;
}
