#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main()
{
int n,i,a[110001],mi=LLONG_MAX,ma=LLONG_MIN,j=0,kq=LLONG_MAX; vector<int> vfi,vse;
cin>>n;
for (i=1; i<=n; i++)
{
cin>>a[i]; ma=max(ma,a[i]); mi=min(mi,a[i]);
}
for (i=1; i<=n; i++)
{
if (a[i]==mi||a[i]==ma)
{
vfi.push_back(i); vse.push_back(a[i]);
}
}
mi=LLONG_MAX;
for (i=1; i<vfi.size(); i++)
{
if (vse[i]!=vse[i-1]) mi=min(mi,vfi[i]-vfi[i-1]);
}
cout<<mi+1;
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKI2RlZmluZSBpbnQgbG9uZyBsb25nCnNpZ25lZCBtYWluKCkKewogICAgaW50IG4saSxhWzExMDAwMV0sbWk9TExPTkdfTUFYLG1hPUxMT05HX01JTixqPTAsa3E9TExPTkdfTUFYOyB2ZWN0b3I8aW50PiB2ZmksdnNlOwogICAgY2luPj5uOwogICAgZm9yIChpPTE7IGk8PW47IGkrKykKICAgIHsKICAgIAljaW4+PmFbaV07IG1hPW1heChtYSxhW2ldKTsgbWk9bWluKG1pLGFbaV0pOwoJfQoJZm9yIChpPTE7IGk8PW47IGkrKykKCXsKCQlpZiAoYVtpXT09bWl8fGFbaV09PW1hKSAKCQl7CgkJCXZmaS5wdXNoX2JhY2soaSk7IHZzZS5wdXNoX2JhY2soYVtpXSk7CgkJfQoJfQoJbWk9TExPTkdfTUFYOwoJZm9yIChpPTE7IGk8dmZpLnNpemUoKTsgaSsrKQkKCXsKCQlpZiAodnNlW2ldIT12c2VbaS0xXSkgbWk9bWluKG1pLHZmaVtpXS12ZmlbaS0xXSk7Cgl9Cgljb3V0PDxtaSsxOwp9Cg==