#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2000;
int cubeta[MAXN + 2];
int color;
int arr[MAXN + 2];
void mapea(int n) {
  set<int> nums;
  for (int i = 1; i <= n; i++) nums.insert(arr[i]);
  map<int, int> val;
  int cnt = 1;
  set<int>::iterator it = nums.begin();
  while (it != nums.end()) {
    val[*it] = cnt;
    cnt++;
    it++;
  }
  for (int i = 1; i <= n; i++) arr[i] = val[arr[i]];
}
int busca(int l, int n) {
  int r = n;
  while (r > l && cubeta[arr[r]] != color) {
    cubeta[arr[r]] = color;
    r--;
  }
  return r + 1;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> arr[i];
  mapea(n);
  int resp = n;
  for (int l = 0; l <= n; l++) {
    color++;
    bool continuar = true;
    for (int i = 1; i <= l; i++) {
      if (cubeta[arr[i]] == color) continuar = false;
      cubeta[arr[i]] = color;
    }
    if (!continuar) break;
    int r = busca(l, n);
    resp = min(resp, r - l - 1);
  }
  cout << resp << '\n';
  return 0;
}
