#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  long long a[n];
  long long ans = 10000;
  unordered_map<long long, long long> mp;
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
    mp[a[i]]++;
  }
  long long fl = 0;
  for (auto u : mp) {
    if (u.second >= 2) {
      fl = 1;
    }
  }
  if (fl == 0) {
    cout << "0\n";
    return 0;
  }
  unordered_map<long long, long long> mp2;
  mp2 = mp;
  long long ptr2 = 0;
  long long k = 0;
  for (long long i = 0; i < n; i++) {
    while (ptr2 < n) {
      if (k == 0)
        mp2[a[ptr2]]--;
      else
        k = 0;
      long long tmp = 0;
      for (auto u : mp2) {
        if (u.second >= 2) {
          tmp = 1;
        }
      }
      if (tmp == 0) {
        ans = min(ans, ptr2 - i + 1);
        k = 1;
        break;
      }
      ptr2++;
    }
    mp2[a[i]]++;
  }
  cout << ans << "\n";
}
