#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, ans;
  scanf("%lld", &n);
  ans = n - 1;
  vector<long long> v(n);
  unordered_map<long long, long long> m;
  for (auto& x : v) scanf("%lld", &x);
  for (long long i = 0; i < n; i++) {
    long long flag = 1;
    for (long long j = 0; j < i; j++) {
      m[v[j]]++;
      if (m[v[j]] == 2) {
        flag = 0;
        break;
      }
    }
    long long last = n;
    for (long long j = n - 1; j >= i; j--) {
      m[v[j]]++;
      if (m[v[j]] == 1)
        last = j;
      else
        break;
    }
    if (flag) ans = min(ans, last - i);
    m.clear();
  }
  cout << ans << '\n';
  return 0;
}
