#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2000 + 7;
int n;
int a[MAXN];
map<int, int> vis;
bool check(int mid) {
  bool flg;
  for (int i = 1; i <= n - mid + 1; i++) {
    flg = false;
    for (int j = i; j <= i + mid - 1; j++) {
      vis[a[j]]--;
    }
    for (int k = 1; k <= n; k++) {
      if (vis[a[k]] > 1) {
        flg = true;
        break;
      }
    }
    for (int j = i; j <= i + mid - 1; j++) {
      vis[a[j]]++;
    }
    if (!flg) return true;
  }
  return false;
}
int main(void) {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    vis[a[i]]++;
  }
  int l = 0, r = n - 1, ans = 0;
  while (l <= r) {
    int mid = (l + r) / 2;
    if (check(mid)) {
      ans = mid;
      r = mid - 1;
    } else
      l = mid + 1;
  }
  cout << ans << endl;
}
