#include <bits/stdc++.h>
using namespace std;
int max(int a, int b) {
  if (a >= b)
    return a;
  else
    return b;
}
int min(int a, int b) {
  if (a <= b)
    return a;
  else
    return b;
}
bool primecheck(int n) {
  if (n == 1) return false;
  if (n == 2 || n == 3) return true;
  if (n % 2 == 0 || n % 3 == 0) return false;
  for (int i = 6; i <= sqrt(n); i += 6) {
    if (n % (i - 1) == 0) return false;
    if (n % (i + 1) == 0) return false;
  }
  return true;
}
long long mod = 1e9 + 7;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  int a[n], r = n - 1, suf;
  for (int i = 0; i < n; i++) cin >> a[i];
  map<int, int> freq;
  for (int i = 0; i < n; i++) {
    bool unique = true;
    for (int j = 0; j < i; j++) {
      freq[a[j]]++;
      if (freq[a[j]] == 2) {
        unique = false;
        break;
      }
    }
    suf = n;
    for (int j = n - 1; j >= i; j--) {
      freq[a[j]]++;
      if (freq[a[j]] == 1)
        suf = j;
      else
        break;
    }
    if (unique) r = min(r, suf - i);
    freq.clear();
  }
  cout << r;
}
