#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
const long long mod = 1e9 + 7;
void chmod(long long& M) {
  if (M >= mod)
    M %= mod;
  else if (M < 0) {
    M += (abs(M) / mod + 1) * mod;
    M %= mod;
  }
}
long long modpow(long long x, long long n) {
  if (n == 0) return 1;
  long long res = modpow(x, n / 2);
  if (n % 2 == 0)
    return res * res % mod;
  else
    return res * res % mod * x % mod;
}
long long power(long long x, long long n) {
  if (n == 0) return 1;
  long long res = power(x, n / 2);
  if (n % 2 == 0)
    return res * res;
  else
    return res * res * x;
}
int getl(int i, int N) { return i == 0 ? N - 1 : i - 1; };
int getr(int i, int N) { return i == N - 1 ? 0 : i + 1; };
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  map<int, int> mp1, mp2;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    ++mp1[a[i]];
  }
  int twice = 0;
  for (auto itr = mp1.begin(); itr != mp1.end(); ++itr)
    if (itr->second >= 2) ++twice;
  if (twice == 0) {
    cout << 0 << endl;
    return 0;
  }
  int ans = n - 1;
  int seen = 0;
  int l = 0, r = 0;
  for (l = 0; l < n; ++l) {
    while (r < n && seen < twice) {
      ++mp2[a[r]];
      if (mp1[a[r]] >= 2 && mp2[a[r]] == mp1[a[r]] - 1) ++seen;
      ++r;
    }
    if (seen < twice) break;
    chmin(ans, r - l);
    if (mp1[a[l]] >= 2 && mp2[a[l]] == mp1[a[l]] - 1) --seen;
    --mp2[a[l]];
  }
  cout << ans << endl;
  return 0;
}
