#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, ans = n - 1;
  cin >> n;
  vector<long long int> a(n);
  map<long long int, long long int> local;
  for (long long int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (long long int i = 0; i < n; i++) {
    bool validPrefix = true;
    for (long long int j = 0; j < i; j++) {
      local[a[j]] += 1;
      if (local[a[j]] > 1) {
        validPrefix = false;
        break;
      }
    }
    long long int min_index_suffix = n;
    for (long long int j = n - 1; j >= i; j--) {
      local[a[j]] += 1;
      if (local[a[j]] == 1) {
        min_index_suffix = j;
      } else
        break;
    }
    if (validPrefix) {
      ans = min(ans, min_index_suffix - i);
    }
    local.clear();
  }
  cout << ans << endl;
  return 0;
}
