#include <bits/stdc++.h>
using namespace std;
const int N = 2005;
int n, T[N];
unordered_map<int, int> MP;
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> T[i];
  int ans = n - 1;
  for (int i = 1; i <= n; i++) {
    MP.clear();
    int rep = 0;
    for (int j = 1; j <= n; j++) {
      MP[T[j]]++;
      if (MP[T[j]] == 2) rep++;
    }
    if (rep == 0) {
      ans = min(ans, 0);
      continue;
    }
    for (int j = i; j <= n; j++) {
      if (MP[T[j]] == 2) rep--;
      MP[T[j]]--;
      if (rep == 0) {
        ans = min(ans, j - i + 1);
        break;
      }
    }
  }
  cout << ans << "\n";
  return 0;
}
