#include <bits/stdc++.h>
using namespace std;
int dirx[] = {-1, -1, -1, 0, 0, 1, 1, 1};
int diry[] = {-1, 0, 1, -1, 1, -1, 0, 1};
vector<string> vec_splitter(string s) {
  s += ',';
  vector<string> res;
  while (!s.empty()) {
    res.push_back(s.substr(0, s.find(',')));
    s = s.substr(s.find(',') + 1);
  }
  return res;
}
void debug_out(vector<string> __attribute__((unused)) args,
               __attribute__((unused)) int idx,
               __attribute__((unused)) int LINE_NUM) {
  cerr << endl;
}
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
  if (idx > 0)
    cerr << ", ";
  else
    cerr << "Line(" << LINE_NUM << ") ";
  stringstream ss;
  ss << H;
  cerr << args[idx] << " = " << ss.str();
  debug_out(args, idx + 1, LINE_NUM, T...);
}
int const lmt = 1e4 + 5;
long long a[lmt];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  a[0] = (int)1e9 + 1;
  for (long long i = 1; i <= n; i++) cin >> a[i];
  map<int, int> fre;
  long long ans = (int)1e9;
  for (long long i = 0; i < n + 1; i++) {
    if (fre[a[i]]) break;
    fre[a[i]]++;
    int j = n;
    while (j > i) {
      if (fre[a[j]]) break;
      fre[a[j]]++;
      j--;
    }
    ans = min(j - i, ans);
    j++;
    while (j <= n) {
      fre[a[j]]--;
      j++;
    }
  }
  cout << ans << "\n";
}
