#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  vector<int> v;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    v.push_back(x);
  }
  map<int, int> make_pair;
  int ans = 0;
  for (int i = 0; i < n; i++) {
    make_pair.clear();
    bool flag = true;
    int idx = i - 1;
    for (int j = 0; j < i; j++) {
      make_pair[v[j]]++;
      if (make_pair[v[j]] == 2) {
        flag = false;
        idx = j - 1;
        make_pair[v[j]]--;
        break;
      }
    }
    int idx2 = i;
    for (int j = n - 1; j >= i; j--) {
      make_pair[v[j]]++;
      if (make_pair[v[j]] == 2) {
        idx2 = j + 1;
        break;
      }
    }
    ans = max(ans, idx + 1 + n - idx2);
    if (!flag) {
      break;
    }
  }
  cout << n - ans << endl;
}
