#include <bits/stdc++.h>
using namespace std;
int ans = 2e9;
void can(int idx, vector<int> a, map<int, int> m) {
  set<int> s;
  for (int i = idx; i < ((long long)(a).size()); i++)
    if (m[a[i]] != 1) s.insert(a[i]);
  for (int i = idx; i < ((long long)(a).size()); i++) {
    m[a[i]]--;
    if (m[a[i]] <= 1) {
      if (s.find(a[i]) != s.end()) {
        s.erase(a[i]);
      }
    }
    if (((long long)(s).size()) == 0) {
      ans = min(ans, i - idx + 1);
      return;
    }
  }
}
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  map<int, int> m;
  int ok = true;
  for (auto &it : a) {
    cin >> it;
    m[it]++;
    ok &= (m[it] <= 1);
  }
  if (ok) {
    cout << "0\n";
    return 0;
  }
  set<int> s;
  for (int i = 0; i < n; i++) {
    can(i, a, m);
    if (s.find(a[i]) != s.end()) {
      break;
    }
    s.insert(a[i]);
  }
  cout << ans << "\n";
}
