#include <bits/stdc++.h>
using namespace std;
const int maxn = 2000 + 5;
int a[maxn];
int b[maxn];
int l[maxn];
int r[maxn];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    b[i] = a[i];
  }
  sort(b + 1, b + n + 1);
  int m = unique(b + 1, b + n + 1) - (b + 1);
  for (int i = 1; i <= n; i++) a[i] = lower_bound(b + 1, b + m + 1, a[i]) - b;
  for (int i = 1; i <= m; i++) {
    l[i] = m + 1;
    r[i] = 0;
  }
  for (int i = 1; i <= n; i++) {
    l[a[i]] = min(l[a[i]], i);
    r[a[i]] = max(r[a[i]], i);
  }
  int ans = n + 1;
  if (m == n)
    ans = 0;
  else {
    for (int i = 1; i <= n; i++) {
      int j;
      for (j = n; j >= i; j--)
        if (r[a[j]] > j || l[a[j]] < i) break;
      ans = min(ans, j - i + 1);
      if (l[a[i]] < i) break;
    }
  }
  printf("%d\n", ans);
  return 0;
}
