#include <bits/stdc++.h>
using namespace std;
const long long INF = 9223372036854775807ll;
const int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1}, inf = 2147483647;
int n, v[2005];
map<int, int> m;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> v[i];
  int ans = n;
  int now = 0;
  for (int i = n; i >= 1; --i) {
    ++m[v[i]];
    if (m[v[i]] == 2) break;
    ++now;
  }
  m.clear();
  ans = min(ans, n - now);
  for (int i = 1; i <= n; ++i) {
    ++m[v[i]];
    if (m[v[i]] == 2) break;
    int in = n;
    now = i;
    for (int j = n; j > i; --j) {
      in = j;
      ++m[v[j]];
      if (m[v[j]] == 2) break;
      ++now;
    }
    ans = min(ans, n - now);
    for (int j = in; j <= n; ++j) --m[v[j]];
  }
  cout << ans << '\n';
  return 0;
}
