#include <bits/stdc++.h>
const int N = 2000 + 5;
using namespace std;
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
int n, now;
int a[N], b[N], c[N], d[N], ds[N];
int work(int l, int r) {
  int sum = 0;
  for (register int i = 1; i <= n; ++i) ds[i] = d[i];
  for (register int i = l; i <= r; ++i) sum += (ds[c[i]] == 2), ds[c[i]] -= 1;
  return sum;
}
bool pd(int x) {
  for (register int i = 1; i <= n - x + 1; ++i)
    if (work(i, i + x - 1) == now) return 1;
  return 0;
}
int main() {
  n = read();
  for (register int i = 1; i <= n; ++i) b[i] = a[i] = read();
  sort(b + 1, b + n + 1);
  for (register int i = 1; i <= n; ++i)
    c[i] = lower_bound(b + 1, b + n + 1, a[i]) - b;
  for (register int i = 1; i <= n; ++i) d[c[i]] += 1;
  for (register int i = 1; i <= n; ++i)
    if (d[i] >= 2) now += 1;
  if (now == 0) return puts("0"), 0;
  int l = 1, r = n, ans = n;
  while (l <= r) {
    int mid = l + r >> 1;
    if (pd(mid))
      ans = mid, r = mid - 1;
    else
      l = mid + 1;
  }
  printf("%d\n", ans);
  return 0;
}
