#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t = 1;
  while (t--) {
    int n;
    cin >> n;
    int a[n];
    unordered_map<int, int> mp, x;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      mp[a[i]]++;
      x[a[i]]++;
    }
    int cnt = 0;
    for (auto it = mp.begin(); it != mp.end(); it++) {
      if (it->second >= 2) cnt++;
    }
    if (cnt == 0) {
      cout << 0 << '\n';
      continue;
    }
    int c, mi = 1e9;
    for (int i = 0; i < n; i++) {
      c = cnt;
      x = mp;
      for (int j = i; j < n; j++) {
        if (x[a[j]] == 2) c--;
        if (c == 0) {
          mi = min(mi, j - i + 1);
          break;
        }
        x[a[j]]--;
      }
    }
    cout << mi << '\n';
  }
  return 0;
}
