#include<bits/stdc++.h>
using namespace std;
int n, a[100005], pre[100005];
int main() {
cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i];
int Ans = 1000000000;
for (int i = 1; i <= n; i++) {
int x = pre[a[i]];
if (x != 0) {
/// x va i
/// so huu cung chieu cao a[x] = a[i]
int kc = i - x;
Ans = min(Ans, kc);
}
pre[a[i]] = i;
}
cout << Ans;
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgppbnQgbiwgYVsxMDAwMDVdLCBwcmVbMTAwMDA1XTsKCmludCBtYWluKCkgewogICAgY2luID4+IG47CiAgICBmb3IgKGludCBpID0gMTsgaSA8PSBuOyBpKyspCiAgICAgICAgY2luID4+IGFbaV07CgogICAgaW50IEFucyA9IDEwMDAwMDAwMDA7CgogICAgZm9yIChpbnQgaSA9IDE7IGkgPD0gbjsgaSsrKSB7CiAgICAgICAgaW50IHggPSBwcmVbYVtpXV07CiAgICAgICAgaWYgKHggIT0gMCkgewogICAgICAgICAgICAvLy8geCAgdmEgaQogICAgICAgICAgICAvLy8gc28gaHV1IGN1bmcgY2hpZXUgY2FvIGFbeF0gPSBhW2ldCiAgICAgICAgICAgIGludCBrYyA9IGkgLSB4OwogICAgICAgICAgICBBbnMgPSBtaW4oQW5zLCBrYyk7CiAgICAgICAgfQogICAgICAgIHByZVthW2ldXSA9IGk7CiAgICB9CiAgICBjb3V0IDw8IEFuczsKfQo=