#include<iostream>
using namespace std;
/*
双指针,滑动窗口思想
*/
const int N = 100010;
int n;
int a[N], s[N]; // s[]维护当前滑动窗口中每个数的个数
int main()
{
cin >> n;
for(int i = 0; i < n; i ++ ) scanf("%d", &a[i]);
int res = 0;
for(int i = 0, j = 0; i < n; i ++ ) // 枚举终点i,j表示区间起点
{
s[a[i]] ++ ;
while(s[a[i]] > 1) // 去除完区间中有重复的点
{
s[a[j]] -- ; // 先减去数,后移动指针
j ++ ;
}
res = max(res, i - j + 1);
}
cout << res;
return 0;
}