#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n;
  cin >> n;
  vector<int> vec(n);
  for (int i = 0; i < n; i++) cin >> vec[i];
  unordered_map<int, int> map;
  set<int> set;
  for (int val : vec) {
    map[val]++;
    if (map[val] == 2) set.insert(val);
  }
  if (set.empty()) {
    cout << 0;
    return;
  }
  int ans = n;
  for (int l = 0; l < n; l++) {
    for (int r = l; !set.empty() && r < n; r++) {
      map[vec[r]]--;
      if (map[vec[r]] == 1) set.erase(vec[r]);
      if (set.empty()) {
        ans = min(ans, r - l + 1);
        while (r >= l) {
          map[vec[r]]++;
          if (map[vec[r]] == 2) set.insert(vec[r]);
          r--;
        }
        break;
      } else if (r == n - 1) {
        while (r >= l) {
          map[vec[r]]++;
          if (map[vec[r]] == 2) set.insert(vec[r]);
          r--;
        }
        break;
      }
    }
  }
  cout << ans;
}
int main() {
  solve();
  return 0;
}
