#include <bits/stdc++.h>
using namespace std;
namespace modular {
const int MOD = 1e9 + 7;
int mul(int a, int b) { return 1ll * a * b % MOD; }
void add(int &a, int b) {
  a += b;
  if (a >= MOD) a -= MOD;
}
void sub(int &a, int b) {
  a -= b;
  if (a < 0) a += MOD;
}
void nm(long long &a) { a %= MOD; }
int lgput(int a, int b) {
  int ans = 1;
  while (b) {
    if (b & 1) ans = mul(ans, a);
    a = mul(a, a);
    b /= 2;
  }
  return ans;
}
}  // namespace modular
using namespace modular;
const int N = 2000;
int a[1 + N];
map<int, int> mp;
int car[1 + 2 * N];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  int nr = 0;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    if (mp[a[i]] == 0) mp[a[i]] = ++nr;
    a[i] = mp[a[i]];
  }
  int j = n;
  while (j > 0 && !car[a[j]]) {
    car[a[j]]++;
    j--;
  }
  j++;
  int ans = j - 1;
  for (int i = 1; i <= n; i++) {
    car[a[i]]++;
    while (j <= n && car[a[i]] > 1) {
      car[a[j]]--;
      j++;
    }
    if (i >= j) {
      ans = 0;
      break;
    }
    if (car[a[i]] > 1) break;
    ans = min(ans, j - i - 1);
  }
  if (ans < 0) ans = 0;
  cout << ans << "\n";
}
