#include <bits/stdc++.h>
using namespace std;
const int N = 2e3;
const int INF = 1e9;
int n;
int a[N + 2];
map<int, int> freq;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  int ans = INF;
  for (int i = 1; i <= n; i++) {
    freq.clear();
    int cnt = 0;
    for (int j = 1; j <= n; j++) {
      freq[a[j]]++;
      cnt += (freq[a[j]] == 2);
    }
    if (cnt == 0) {
      cout << "0\n";
      return 0;
    }
    for (int j = i; j <= n; j++) {
      freq[a[j]]--;
      cnt -= (freq[a[j]] == 1);
      if (cnt == 0) ans = min(ans, j - i + 1);
    }
  }
  cout << ans << '\n';
  return 0;
}
