#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0, f = 1, c = getchar();
  for (; !isdigit(c); c = getchar())
    if (c == '-') f ^= 1;
  for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
  return f ? x : -x;
}
int n, a[2005];
int v[2005], m;
int cnt[2005];
set<int> st[2005];
int ori[2005];
int main() {
  n = read();
  for (int i = 0; i < (int)(n); ++i) a[i] = read();
  for (int i = 0; i < (int)(n); ++i) v[m++] = a[i];
  sort(v, v + m);
  m = unique(v, v + m) - v;
  for (int i = 0; i < (int)(n); ++i) a[i] = lower_bound(v, v + m, a[i]) - v;
  for (int i = 0; i < (int)(n); ++i) ori[a[i]]++;
  int ans = n;
  for (int l = 0; l < (int)(n); ++l) {
    for (int i = 0; i < (int)(m); ++i) cnt[i] = ori[i];
    for (int i = 0; i < (int)(n + 1); ++i) st[i].clear();
    for (int i = 0; i < (int)(m); ++i) st[cnt[i]].insert(i);
    int mx = 0;
    for (int i = 0; i < (int)(m); ++i) mx = max(mx, cnt[i]);
    if (mx == 1) {
      puts("0");
      return 0;
    }
    for (int r = l; r < n; ++r) {
      cnt[a[r]]--;
      st[cnt[a[r]] + 1].erase(a[r]);
      st[cnt[a[r]]].insert(a[r]);
      while (st[mx].empty()) --mx;
      if (mx == 1) {
        ans = min(ans, r - l + 1);
        break;
      }
    }
  }
  printf("%d\n", ans);
  return 0;
}
