#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2005;
struct Map {
  int data[MAXN], cnt;
  void init() { cnt = 0; }
  void push(int v) { data[cnt++] = v; }
  void solve() {
    sort(data, data + cnt);
    cnt = unique(data, data + cnt) - data;
  }
  int rank(int k) { return data[k - 1]; }
  int find(int v) { return lower_bound(data, data + cnt, v) - data + 1; }
};
int n;
int a[MAXN];
Map mapp;
int buc[MAXN];
bool judge(int mid) {
  for (int l = 1; l + mid - 1 <= n; l++) {
    memset(buc, 0, sizeof(buc));
    bool flag = true;
    for (int i = 1; i <= n; i++) {
      if (l <= i && i <= l + mid - 1) {
        continue;
      }
      if (buc[a[i]]) {
        flag = false;
        break;
      }
      buc[a[i]]++;
    }
    if (flag) {
      return true;
    }
  }
  return false;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> n;
  mapp.init();
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    mapp.push(a[i]);
  }
  mapp.solve();
  for (int i = 1; i <= n; i++) {
    a[i] = mapp.find(a[i]);
  }
  int l = 0, r = n;
  while (l < r) {
    int mid = (l + r) >> 1;
    if (judge(mid)) {
      r = mid;
    } else {
      l = mid + 1;
    }
  }
  cout << l << endl;
  return 0;
}
