#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n;
  cin >> n;
  long long a[n];
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
  }
  long long ans = n - 1;
  std::map<long long, long long> mp;
  for (long long i = 0; i < n; i++) {
    bool flag = true;
    for (long long j = 0; j < i; j++) {
      mp[a[j]]++;
      if (mp[a[j]] == 2) {
        flag = false;
        break;
      }
    }
    long long temp = n;
    for (long long j = n - 1; j >= i; j--) {
      mp[a[j]]++;
      if (mp[a[j]] == 1) {
        temp = j;
      } else {
        break;
      }
    }
    if (flag) {
      ans = min(ans, temp - i);
    }
    mp.clear();
  }
  cout << ans << '\n';
}
