#include <bits/stdc++.h>
using namespace std;
const int N = 2e3 + 5;
int a[N];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
  }
  int ans = n - 1;
  set<int> seen;
  for (int i = 0; i < n; ++i) {
    bool ok = true;
    for (int j = 0; j <= i; ++j) {
      if (seen.count(a[j])) {
        ok = false;
        break;
      }
      seen.emplace(a[j]);
    }
    if (!ok) continue;
    int j = n - 1;
    while (!seen.count(a[j])) {
      seen.insert(a[j--]);
    }
    ans = min(ans, j - i);
    seen.clear();
  }
  seen.clear();
  int i = 0;
  for (; i < n; ++i) {
    if (seen.count(a[i])) break;
    seen.insert(a[i]);
  }
  ans = min(ans, n - i);
  seen.clear();
  reverse(a, a + n);
  for (i = 0; i < n; ++i) {
    if (seen.count(a[i])) break;
    seen.insert(a[i]);
  }
  ans = min(ans, n - i);
  cout << ans << '\n';
}
