#include <bits/stdc++.h>
using namespace std;
template <class T>
struct rge {
  T b, e;
};
template <class T>
rge<T> range(T i, T j) {
  return rge<T>{i, j};
}
struct debug {
  template <class T>
  debug& operator<<(const T&) {
    return *this;
  }
};
using ll = long long;
template <typename T>
void min_self(T& a, T b) {
  a = min(a, b);
}
template <typename T>
void max_self(T& a, T b) {
  a = max(a, b);
}
void compress(vector<int>& a) {
  vector<int> b = a;
  sort(b.begin(), b.end());
  b.resize(unique(b.begin(), b.end()) - b.begin());
  for (int& x : a) {
    int i = lower_bound(b.begin(), b.end(), x) - b.begin();
    x = i;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  compress(a);
  auto OK = [&](int l) {
    vector<int> left, right, seen(n);
    bool f = true;
    for (int i = n - 1; i >= l; --i) {
      right.push_back(a[i]);
      if (seen[a[i]]) {
        f = false;
      }
      seen[a[i]] = true;
    }
    if (f) {
      return true;
    }
    for (int start = 1; start <= n - l; start++) {
      right.pop_back();
      left.push_back(a[start - 1]);
      vector<int> now(n);
      bool ok = true;
      for (int x : left) {
        if (now[x]) {
          ok = false;
        }
        now[x]++;
      }
      for (int x : right) {
        if (now[x]) {
          ok = false;
        }
        now[x]++;
      }
      if (ok) {
        return true;
      }
    }
    return false;
  };
  int lo = 0, hi = n;
  while (lo < hi) {
    int m = (lo + hi) / 2;
    if (OK(m)) {
      hi = m;
    } else {
      lo = m + 1;
    }
  }
  cout << hi << "\n";
}
