#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 = 0; i < n; ++i)
{
//cout << a1[i] << endl;
if (a1[i] > 1)
{
mx = max(mx, a1[i]);
}
}
cout << mx + 1;
return 0;
}