#include <iostream>
using namespace std;
const int N = 100010;
int n;
int a[N], s[N];
int main()
{
scanf("%d", &n);
for (int i = 0; i < n; i ++ ) scanf("%d", &a[i]);
int ans = 0;
for (int i = 0, j = 0; i < n; i ++ )
{
int x = a[i];
s[x] ++ ;
while (s[x] > 1)
{
s[a[j]] -- ;
j ++ ;
}
ans = max(ans, i - j + 1);
}
printf("%d\n", ans);
return 0;
}