#include <bits/stdc++.h>
using namespace std;
int N = 3000001;
int M = 1000001;
int main() {
vector<vector<int>>v ;
v.resize(N) ;
int n;
scanf("%d" , &n) ;
for (int i =0 ; i<n ; ++i) {
int x ;
cin>>x;
x+=M ;
v[x].push_back(i) ;
}
int mx = 1;
for(int i =0 ; i<N ; ++i) {
if (v[i].size()){
// cout<< v[i][0]<<" "<<v[i][v[i].size()-1]<<endl;
mx = max(mx , v[i][v[i].size()-1]-v[i][0]+1) ;
}
}
cout<<mx<<endl;
return 0;
}