#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  long long int n;
  cin >> n;
  long long int arr[n];
  long long int cnt = 0;
  map<long long int, long long int> make_pair;
  for (long long int i = 0; i < n; i++) {
    cin >> arr[i];
    if (make_pair[arr[i]] == 1) {
      cnt++;
    }
    make_pair[arr[i]]++;
  }
  if (cnt == 0) {
    cout << "0";
    return 0;
  }
  long long int ans = n - 1;
  for (long long int i = 0; i < n; i++) {
    long long int temp = cnt;
    map<long long int, long long int> mp1(make_pair);
    for (long long int j = i; j < n; j++) {
      if (mp1[arr[j]] == 2) {
        temp--;
      }
      if (temp == 0) ans = min(ans, j - i + 1);
      mp1[arr[j]]--;
    }
  }
  cout << ans;
  return 0;
}
