#include <bits/stdc++.h>
using namespace std;
int n;
long a[2008];
unordered_map<int, int> freq;
bool check(int size) {
  if (size == 0) {
    for (auto val : freq) {
      if (val.second > 1) return false;
    }
    return true;
  } else {
    int upper = n - size + 1;
    int i = 0, j = size - 1, temp;
    unordered_map<int, int> mp;
    for (int k = i; k <= j; k++) {
      mp[a[k]]++;
    }
    for (; i < upper;) {
      bool flag = 1;
      for (auto val : freq) {
        temp = val.second - mp[val.first];
        if (temp > 1) flag = 0;
      }
      if (flag) return true;
      mp[a[i]]--;
      i++;
      j++;
      mp[a[j]]++;
    }
    return false;
  }
}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    freq[a[i]]++;
  }
  int low = -1, high = n - 1, mid;
  while ((high - low) > 1) {
    mid = low + (high - low) / 2;
    bool c = check(mid);
    if (c)
      high = mid;
    else
      low = mid;
  }
  cout << high << endl;
}
