#include <iostream>
using namespace std;
long long n, a[1000001];
long long 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;
}
}
long long mx = 0;
for (int i = 0; i < n; ++i)
{
//cout << a1[i] << endl;
mx = max(mx, a1[i]);
}
cout << mx + 1;
return 0;
}