#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
const long long Mod = 1000000007;
int a[2005];
map<int, int> mp, vis;
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  ;
  int n;
  cin >> n;
  int f = 0;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    mp[a[i]]++;
    if (mp[a[i]] > 1) {
      f = 1;
      vis[a[i]] = 1;
    }
  }
  int cnt = 0;
  for (auto ff : vis) {
    cnt++;
  }
  if (f == 0) {
    cout << 0 << endl;
    return 0;
  }
  int zx = 3000;
  int l = 1, r = 0;
  while (r <= n) {
    r++;
    mp[a[r]]--;
    {
      if (mp[a[r]] == 1) cnt--;
    }
    while (l <= r) {
      if (mp[a[l]] < 1) {
        mp[a[l]]++;
        l++;
      } else
        break;
    }
    if (cnt == 0) zx = min(zx, r - l + 1);
  }
  cout << zx << endl;
  return 0;
}
