#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long INFMAX = 1e9;
const long long INFMIN = -1e9;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
const double epsilon = 1e-9;
const double PI = acos(-1.00);
const int MAXN = 2e3 + 5;
int n, a[MAXN];
int res(INFMAX);
set<int> s;
map<int, int> m;
void Input() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    s.insert(a[i]);
    m[a[i]]++;
  }
}
void Solve() {
  set<int> tmps = s;
  map<int, int> tmpm = m;
  if (s.size() == n) {
    res = 0;
    return;
  }
  for (int i = 1; i <= n; i++) {
    for (int j = i; j <= n; j++) {
      m[a[j]]--;
      if (m[a[j]] == 0) s.erase(a[j]);
      if (s.size() == n - (j - i + 1)) res = min(res, j - i + 1);
    }
    s = tmps;
    m = tmpm;
  }
}
void Output() { printf("%d", res); }
int main() {
  Input();
  Solve();
  Output();
  return 0;
}
