#include <iostream>
using namespace std;
int n, a[1000001];
int a1[1000001];
int main(){
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
int ans = 0;
cin >> n;
for (int i = 1; i <= n; ++i)
{
int x;
cin >> x;
if (a[x] > 0)
{
a1[x] = i - a[x];
}else{
a[x] = i;
}
}
int mx = 0;
for (int i = 1; i <= n; ++i)
{
//cout << a1[i] << endl;
mx = max(mx, a1[i]);
}
cout << mx + 1;
return 0;
}