PKU3320

#include<iostream>
#include<map>
#include<set>
using namespace std;

int P;

int main(){
	cin >> P;
	int a[P];
	set<int> all;
	for(int i = 0; i < P;i++){
		cin >> a[i];
		all.insert(a[i]);
	}
	int n = all.size();
	int s = 0, t = 0, ph = 0;
	map<int, int> count; //事柄→出現数の対応
	int res = P;
	while(true){
		while(t < P && ph < n){
			if(count[a[t++]]++ == 0){
				ph++;
			}
		}
		if(ph < n)break;
		res = min(res, t - s);
		if(--count[a[s++]] == 0){
			ph--;
		}
	}
	cout << res << endl;
	return 0;
}