#include <bits/stdc++.h>
using namespace std;
map<int, int> check;
int main() {
  int n, arr[100005];
  int ans = 0;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> arr[i];
  }
  for (int i = 0; i <= n; i++) {
    check.clear();
    int ret = 0;
    for (int j = 1; j <= i; j++) {
      if (check.find(arr[j]) != check.end()) {
        ret = -1;
        break;
      }
      check[arr[j]] = 1;
      ret++;
      ans = max(ans, ret);
    }
    if (ret == -1) continue;
    ans = max(ans, ret);
    for (int j = n; j > i; j--) {
      if (check.find(arr[j]) != check.end()) {
        ret = -1;
        break;
      }
      check[arr[j]] = 1;
      ret++;
      ans = max(ans, ret);
    }
  }
  cout << n - ans << endl;
  return 0;
}
