#include <bits/stdc++.h>
using namespace std;
const int INF = 1000 * 1000 * 1000 + 7;
const long long LINF = 1LL * INF * INF;
const int MAX = 1e6 + 7;
const double PI = acos(-1.);
const double EPS = 1e-7;
const int MAXN = 100005;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
int cnt[2005];
int main() {
  ios_base::sync_with_stdio(0);
  int n;
  cin >> n;
  set<int> st;
  vector<int> a(n);
  for (int i = 0; i < (n); ++i) {
    cin >> a[i];
    st.insert(a[i]);
  }
  if (((int)st.size()) == n) {
    cout << 0 << "\n";
    return 0;
  }
  vector<int> b = a;
  sort(b.begin(), b.end());
  for (int i = 0; i < (n); ++i) {
    a[i] = lower_bound(b.begin(), b.end(), a[i]) - b.begin();
    cnt[a[i]]++;
  }
  int ans = INF, c = ((int)st.size());
  for (int i = 0; i < (n); ++i) {
    int kol = 0;
    for (int j = 0; j < (n); ++j) {
      kol += cnt[a[j]] <= 1;
    }
    for (int j = i; j < (n); ++j) {
      cnt[a[j]]--;
      if (cnt[a[j]] == 1) {
        ++kol;
      }
      if (kol == c) {
        ans = min(j - i + 1, ans);
      }
    }
    for (int j = i; j < (n); ++j) {
      cnt[a[j]]++;
    }
  }
  cout << ans;
  return 0;
}
