#include <bits/stdc++.h>
using namespace std;
constexpr long long INF = 1e15;
void run() {
  long long n;
  cin >> n;
  vector<long long> a(n);
  for (auto &el : a) cin >> el;
  auto t = a;
  sort(t.begin(), t.end());
  t.resize(unique(t.begin(), t.end()) - t.begin());
  map<long long, long long> to;
  for (long long i = 0; i < t.size(); i++) {
    to[t[i]] = i;
  }
  for (auto &el : a) el = to[el];
  vector<long long> cnt(n);
  for (auto &el : a) {
    cnt[el]++;
  }
  bool fl = 0;
  for (auto &el : cnt) {
    if (el > 1) fl = 1;
  }
  if (!fl) {
    cout << 0;
    return;
  }
  long long ans = n;
  for (long long i = 0; i < n; i++) {
    long long l = i - 1;
    long long r = n;
    bool ch = 0;
    while (l + 1 < r) {
      auto cc = cnt;
      long long m = (l + r) >> 1;
      for (long long j = i; j <= m; j++) {
        cc[a[j]]--;
      }
      bool f = 1;
      for (auto el : cc) {
        if (el > 1) f = 0;
      }
      if (f) {
        r = m;
        ch = 1;
      } else
        l = m;
    }
    if (ch) ans = min(r - i + 1, ans);
  }
  cout << ans;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  long long t = 1;
  while (t--) {
    run();
  }
  return 0;
}
