#include <bits/stdc++.h>
using namespace std;
map<int, int> mp;
int mn = 1000000005;
int reminder = 1000000005;
int main() {
  int n;
  cin >> n;
  int arr[n + 1];
  for (int i = 1; i <= n; i++) {
    cin >> arr[i];
    if (mp[arr[i]] == 0) {
      mp[arr[i]] = i;
    } else {
      if (arr[i] < reminder) {
        int mm = (i - mp[arr[i]]);
        mp[arr[i]] = i;
        mn = mm;
        reminder = arr[i];
      } else if (arr[i] == reminder) {
        int mm = (i - mp[arr[i]]);
        mp[arr[i]] = i;
        mn = min(mn, mm);
        reminder = arr[i];
      }
    }
  }
  cout << mn << endl;
  return 0;
}
