#include // #include using namespace std; // using namespace atcoder; using ll = long long; using ull = unsigned long long; using P = pair; #define rep(i,n) for(ll i = 0;i < (ll)n;i++) #define ALL(x) (x).begin(),(x).end() #define MOD 1000000007 int main(){ int n; cin >> n; vector a(n); rep(i,n)cin >> a[i]; if(!n){ cout << 0 << "\n"; return 0; } int l = 1,r = n+1; while(r-l > 1){ int mid = (l+r)/2; vector cnt(2000000); int h = 0; bool is = false; rep(i,mid-1)if(cnt[a[i]]++ == 1)h++; for(int i = mid-1;i < n;i++){ if(i-mid >= 0)if(cnt[a[i]]-- == 2)h--; if(cnt[a[i]]++ == 1)h++; if(!h)is = true; } if(is)l = mid; else r = mid; } cout << l << "\n"; return 0; }