#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  long long int n;
  cin >> n;
  vector<long long int> v(n + 1);
  map<long long int, long long int> pre, pre1;
  for (long long int i = 1; i <= n; i++) {
    cin >> v[i];
  }
  long long int ans = 0;
  for (long long int i = n; i >= 1; i--) {
    if (pre1[v[i]] == 0)
      pre1[v[i]] = i;
    else if (ans == 0)
      ans = i;
  }
  long long int en = ans;
  for (long long int i = 1; i <= n; i++) {
    if (pre[v[i]] == 0) {
      en = max(en, pre1[v[i]]);
      pre[v[i]] = i;
      ans = min(ans, en - i);
    } else
      break;
  }
  cout << ans << '\n';
  return 0;
}
