#include <bits/stdc++.h>
long long int M = 1000000007;
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cout << setprecision(25);
  ;
  long long int T = 1;
  while (T--) {
    int n;
    cin >> n;
    vector<int> v(n);
    for (int i = 0; i < n; i++) cin >> v[i];
    int ans = n - 1;
    for (int i = 0; i < n; i++) {
      bool pos = true;
      map<int, int> m;
      for (int j = 0; j < i; j++) {
        m[v[j]]++;
        if (m[v[j]] > 1) {
          pos = false;
          break;
        }
      }
      int ind = n;
      for (int j = n - 1; j >= i; j--) {
        m[v[j]]++;
        if (m[v[j]] == 1)
          ind = j;
        else
          break;
      }
      if (pos) ans = min(ans, ind - i);
      m.clear();
    }
    cout << ans;
  }
}
