#include<bits/stdc++.h>
using namespace std;
int n,cc,dm;
deque<int>p;
map<int,bool>m;
signed main()
{
cin>>n;
int a[n+1];
for (int i=1;i<=n;i++)
{
cin>>a[i];
m[a[i]]=false;
}
int res=0;
for (int i=1;i<=n;i++)
{
if (m[a[i]]==false)
{
p.push_front(i);
m[a[i]]=true;
}
else if (m[a[i]]==true)
{
while (!p.empty()&&a[p.back()]!=a[i])
{
p.pop_back();
}
if (!p.empty()) p.pop_back();
p.push_front(i);
}
cc=p.size();
res=max(res,cc);
}
cout<<res;
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKaW50IG4sY2MsZG07CmRlcXVlPGludD5wOwptYXA8aW50LGJvb2w+bTsKc2lnbmVkIG1haW4oKQp7CiAgICBjaW4+Pm47CiAgICBpbnQgYVtuKzFdOwogICAgZm9yIChpbnQgaT0xO2k8PW47aSsrKQogICAgewogICAgICAgIGNpbj4+YVtpXTsKICAgICAgICBtW2FbaV1dPWZhbHNlOwogICAgfQogICAgaW50IHJlcz0wOwogICAgZm9yIChpbnQgaT0xO2k8PW47aSsrKQogICAgewogICAgICAgIGlmIChtW2FbaV1dPT1mYWxzZSkKICAgICAgICB7CiAgICAgICAgICAgIHAucHVzaF9mcm9udChpKTsKICAgICAgICAgICAgbVthW2ldXT10cnVlOwogICAgICAgIH0KICAgICAgICBlbHNlIGlmIChtW2FbaV1dPT10cnVlKQogICAgICAgIHsKICAgICAgICAgICAgd2hpbGUgKCFwLmVtcHR5KCkmJmFbcC5iYWNrKCldIT1hW2ldKQogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICBwLnBvcF9iYWNrKCk7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKCFwLmVtcHR5KCkpIHAucG9wX2JhY2soKTsKICAgICAgICAgICAgcC5wdXNoX2Zyb250KGkpOwogICAgICAgIH0KICAgICAgICBjYz1wLnNpemUoKTsKICAgICAgICByZXM9bWF4KHJlcyxjYyk7CiAgICB9CiAgICBjb3V0PDxyZXM7Cn0K