#include<stdio.h>
#include<map>
#include<set>
using namespace std;
const int MAX_P = 1000005;
int a[MAX_P];
int min(int a,int b){
return a<b?a:b;
}
int main(){
int p;
int i, j ;
while(scanf("%d",&p)!=EOF){
//set去重
set<int> all;
all.clear();
for(i = 0 ; i < p ; i ++){
scanf("%d",&a[i]);
all.insert(a[i]);
}
int n = all.size();
//map映射
map<int,int> count;
count.clear();
int ans = p;
int num = 0;
for(int s=0,t=0;;){
while(t<p && num < n){
if(count[a[t++]] ++ == 0){
num++;
}
}
if(num<n)break;
ans =min(ans,t-s);
if(count[a[s++]] -- == 1 ){
num --;
}
}
printf("%d\n",ans);
}
return 0;
}