#include <bits/stdc++.h>
using namespace std;
const int N = 10e5, MOD = 998244353;
map<int, int> mp, np;
void SlayMe() {
  bool boo = 0;
  int n, mn = 2001;
  scanf("%d", &n);
  int arr[n + 1];
  for (int i = 1; i <= n; i++) scanf("%d", &arr[i]);
  for (int i = 1; i <= n; i++) {
    if (i > 1) mp[arr[i - 1]]++;
    if (mp[arr[i - 1]] > 1) {
      boo = 1;
      break;
    }
    for (int j = n; j >= i; j--) {
      if (j < n && mp[arr[j + 1]] + np[arr[j + 1]] == 0)
        np[arr[j + 1]]++;
      else if (mp[arr[j + 1]] + np[arr[j + 1]] > 0) {
        boo = 1;
        break;
      }
      mn = min(j - i + 1, mn);
    }
    np.clear();
  }
  if (boo)
    printf("%d", mn);
  else
    printf("0");
}
int main() { SlayMe(); }
