#include <bits/stdc++.h>
using namespace std;
long long ncrp(long long n, long long r, long long p) {
  long long C[r + 1];
  memset(C, 0, sizeof(C));
  C[0] = 1;
  for (long long i = 1; i <= n; i++)
    for (long long j = min(i, r); j >= 1; j--) C[j] = (C[j] + C[j - 1]) % p;
  return C[r];
}
long long mod_exp(long long x, long long y, long long mm) {
  x %= mm;
  if (y == 0)
    return (1);
  else if (y % 2 == 0)
    return (mod_exp((x * x) % mm, y / 2, mm));
  else
    return ((x * mod_exp((x * x) % mm, (y - 1) / 2, mm)) % mm);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n, d, s = 0, ans = 1000000000;
  map<long long, long long> z;
  map<long long, long long>::iterator it;
  cin >> n;
  long long a[n];
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
    z[a[i]]++;
  }
  for (it = z.begin(); it != z.end(); it++) {
    if (it->second > 1) s++;
  }
  for (long long i = 0; i < n; i++) {
    map<long long, long long> y;
    d = 0;
    for (long long j = i; j <= n - 1; j++) {
      y[a[j]]++;
      if ((z[a[j]] > 1) && (z[a[j]] - y[a[j]] == 1)) d++;
      if (d == s) ans = min(ans, j - i + 1);
    }
  }
  if (s == 0)
    cout << s;
  else
    cout << ans;
  return 0;
}
