#include <bits/stdc++.h>
using namespace std;
const long long FASTIO = []() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  return 0;
}();
template <typename T>
class seg_tree {
  long long p = 1;
  function<T(T, T)> key;
  T begi;

 public:
  vector<T> t;
  seg_tree(vector<T>& v, function<T(T, T)> func, T a) : key(func), begi(a) {
    long long n = v.size();
    while (p < n) p <<= 1;
    t.resize(2 * p, begi);
    for (long long i = 0; i < n; i++) {
      t[i + p] = v[i];
    }
    for (long long i = p - 1; i > 0; i--) {
      t[i] = key(t[i << 1], t[(i << 1) | 1]);
    }
  }
  seg_tree(long long Size, function<T(T, T)> func, T& c) : key(func), begi(c) {
    while (p < Size) p <<= 1;
    t.resize(2 * p, begi);
  }
  T get(long long l, long long r) {
    l += p;
    r += p;
    T ans = begi;
    while (l <= r) {
      if (l & 1) ans = key(ans, t[l++]);
      if ((r & 1) == 0) ans = key(ans, t[r--]);
      l >>= 1;
      r >>= 1;
    }
    return ans;
  }
  void add(long long i, T val) {
    i += p;
    t[i] += val;
    i >>= 1;
    while (i > 0) {
      t[i] = key(t[i << 1], t[(i << 1) | 1]);
      i >>= 1;
    }
  }
  void update(long long i, T val) {
    i += p;
    t[i] = val;
    i >>= 1;
    while (i > 0) {
      t[i] = key(t[i << 1], t[(i << 1) | 1]);
      i >>= 1;
    }
  }
};
signed main() {
  long long n;
  cin >> n;
  map<long long, long long> m;
  vector<long long> v(n + 1);
  vector<long long> cnt;
  long long t = 0;
  for (long long i = 1; i <= n; i++) {
    cin >> v[i];
    if (m.find(v[i]) == m.end()) {
      m[v[i]] = ++t;
      v[i] = t;
    } else
      v[i] = m[v[i]];
    while (v[i] >= cnt.size()) cnt.push_back(0);
    cnt[v[i]]++;
  }
  seg_tree<long long> tree(
      cnt, [](long long a, long long b) { return a < b ? b : a; }, -1);
  long long ans = 1e9;
  long long j = 1;
  for (long long i = 1; i <= n; i++) {
    while (j <= n + 1) {
      if (tree.t[1] <= 1) {
        ans = min(ans, j - i);
        break;
      }
      if (j <= n) {
        tree.add(v[j], -1);
        j++;
      } else {
        break;
      }
    }
    tree.add(v[i], 1);
  }
  cout << ans;
}
