#include <bits/stdc++.h>
using namespace std;
long long a[2001];
bool c[2001];
map<long long, int> m;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  for (int i = 0; i < (n); i++) cin >> a[i];
  int ans = 0;
  memset(c, false, sizeof(c));
  int cnt = 0;
  int l = 0;
  while (l < n) {
    if (m[a[l]] == 0) {
      m[a[l]] += 1;
      l += 1;
      cnt += 1;
    } else {
      l -= 1;
      break;
    }
  }
  if (l == n) l = n - 1;
  int r = n - 1;
  while (r > l) {
    if (m[a[r]] == 0) {
      m[a[r]] += 1;
      r -= 1;
      cnt += 1;
    } else {
      break;
    }
  }
  ans = max(ans, cnt);
  while (l >= 0) {
    m[a[l--]] -= 1;
    cnt -= 1;
    while (r > l && m[a[r]] == 0) {
      m[a[r]] += 1;
      cnt += 1;
      r -= 1;
    }
    ans = max(ans, cnt);
  }
  cout << n - ans << '\n';
}
