#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
map<int, int> m;
int main() {
  int n;
  scanf("%d", &n);
  int mn = 1e6;
  int x;
  int g = 1e9;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &x);
    if (!m[x]) {
      m[x] = i;
    } else {
      if (g >= x) {
        if (g == x)
          mn = min(mn, i - m[x]);
        else
          mn = i - m[x];
        m[x] = i;
        g = x;
      }
    }
  }
  printf("%d", mn);
  return 0;
}
