#include <bits/stdc++.h>
using namespace std;
void debug_out() { cerr << char(8) << char(8) << "]\n"; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << to_string(H) << ", ";
  debug_out(T...);
}
const int INF = 1e9;
const long long LINF = 1e18;
namespace io {
void setIn(const char* in) { freopen(in, "r", stdin); }
void setOut(const char* out) { freopen(out, "w", stdout); }
template <class T1, class T2>
ostream& operator<<(ostream& out, const pair<T1, T2> p) {
  return out << '[' << p.first << ", " << p.second << "]";
}
template <class T1, class T2>
istream& operator>>(istream& in, pair<T1, T2>& p) {
  return in >> p.first >> p.second;
}
template <class T>
ostream& operator<<(ostream& out, const vector<T> v) {
  out << "{ ";
  int sz = (int)v.size();
  for (int i = 0; i < sz; i++) {
    out << v[i];
    if (i != sz - 1) out << ", ";
  }
  return out << " }";
}
inline int rdi() {
  int v;
  cin >> v;
  return v;
}
inline long long rdll() {
  long long v;
  cin >> v;
  return v;
}
inline string rds() {
  string s;
  cin >> s;
  return s;
}
inline char rdc() {
  char c;
  cin >> c;
  return c;
}
template <class T>
void rdv(T beg_iter, T end_iter) {
  for (; beg_iter != end_iter; ++beg_iter) cin >> *beg_iter;
}
inline void wri(const int v) { cout << v; }
inline void wrll(const long long& v) { cout << v; }
inline void wrs(const string& s) { cout << s; }
inline void wrc(const char c) { cout << c; }
template <class T>
void wrv(T beg_iter, T end_iter, string separator = " ",
         string end_of_line = "\n") {
  for (; beg_iter != end_iter; ++beg_iter) {
    cout << *beg_iter;
    cout << separator;
  }
  cout << end_of_line;
}
}  // namespace io
using namespace io;
vector<int> a;
int n;
bool ok(int sz) {
  multiset<int> ms;
  set<int> s;
  for (int i = 0; i < n - sz; i++) {
    ms.insert(a[i]);
    s.insert(a[i]);
  }
  if (ms.size() == s.size()) return true;
  for (int j = n - sz - 1, i = n - 1; j >= 0; i--, j--) {
    ms.erase(ms.find(a[j]));
    if (ms.find(a[j]) == ms.end()) {
      s.erase(a[j]);
    }
    ms.insert(a[i]);
    s.insert(a[i]);
    if (ms.size() == s.size()) return true;
  }
  return false;
}
void solve() {
  n = rdi();
  a.resize(n);
  rdv((a).begin(), (a).end());
  int l = 0, r = n - 1;
  while (l <= r) {
    int m = (l + r) >> 1;
    bool temp = ok(m);
    if (temp) {
      r = m - 1;
    } else {
      l = m + 1;
    }
  }
  cout << l << '\n';
}
int main() {
  int t = 1;
  while (t--) solve();
  return 0;
}
