#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> in(n);
  for (auto &i : in) cin >> i;
  int lu = 0, ru = 0, mu = 0;
  int ans = n + 5;
  int u = 0;
  map<int, int> res;
  for (int i = 0; i < n; i++) {
    res[in[i]]++;
    if (res[in[i]] == 2) break;
    lu++;
  }
  res.clear();
  for (int i = n - 1; i >= 0; i--) {
    res[in[i]]++;
    if (res[in[i]] == 2) break;
    ru++;
  }
  res.clear();
  int l = 0, r = 0;
  for (int i = 0; i < n; i++) {
    res[in[i]]++;
    if (res[in[i]] == 2) {
      r = 0;
      for (int j = n - 1; j > i; j--) {
        res[in[j]]++;
        if (res[in[j]] >= 2) break;
        r++;
      }
      mu = max(mu, l + r);
      break;
    } else {
      l++;
      vector<int> temp;
      r = 0;
      for (int j = n - 1; j > i; j--) {
        res[in[j]]++;
        if (res[in[j]] == 2) {
          res[in[j]]--;
          break;
        }
        temp.push_back(in[j]);
        r++;
      }
      for (int tt : temp) res[tt] = 0;
      mu = max(mu, l + r);
      r = 0;
    }
  }
  u = max(lu, max(ru, mu));
  cout << n - u << endl;
}
