#include <bits/stdc++.h>
using namespace std;
map<int, int> book1, book2;
int main() {
  int n;
  int a[2005];
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  int ans = 99999;
  int p = 1, q = n;
  while (p <= n) {
    if (book1[a[p]]) {
      break;
    } else {
      book1[a[p]] = p;
    }
    p++;
  }
  p--;
  ans = n - p;
  while (q >= 1) {
    if (book2[a[q]]) {
      if (ans > q - p) ans = q - p;
      break;
    } else {
      book2[a[q]] = 1;
    }
    if (book1[a[q]] && p >= book1[a[q]]) {
      if (ans > q - p) ans = q - p;
      p = book1[a[q]] - 1;
    }
    q--;
  }
  printf("%d\n", ans);
  return 0;
}
