#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int dr8[] = {0, 0, 1, -1, 1, 1, -1, -1};
int dc8[] = {1, -1, 0, 0, -1, 1, -1, 1};
int dr4[] = {0, 1, -1, 0};
int dc4[] = {1, 0, 0, -1};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  int a[n];
  map<int, int> m;
  set<int> s;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    m[a[i]]++;
    s.insert(a[i]);
  }
  if (s.size() == n) {
    cout << 0;
    return 0;
  }
  int mn = 1000000009;
  for (int i = 0; i < n; i++) {
    for (int j = i; j < n; j++) {
      int c = m[a[j]];
      if (c == 1) {
        m[a[j]]--;
        s.erase(s.find(a[j]));
      } else {
        m[a[j]]--;
      }
      if (s.size() == (n - (j - i + 1))) {
        mn = min(mn, j - i + 1);
        break;
      }
    }
    m.clear();
    s.clear();
    for (int j = 0; j < n; j++) {
      m[a[j]]++;
      s.insert(a[j]);
    }
  }
  cout << mn;
}
