#include<cstdio>
#include<algorithm>
#include<cstring>
#include<map>
#include<vector>
using namespace std;
vector<int> v[105];
int main()
{
int n,c;
int t;
int ans=0,sam;
scanf("%d%d",&n,&c);
for(int i=1;i<=n;i++)
{
scanf("%d",&t);
v[t].push_back(i);
}
for(int i=1;i<=c;i++)
{
if(v[i].size()==0)
continue;
for(int j=i+1;j<=c;j++)
{
if(v[j].size()==0)
continue;
sam=0;
int x=i,y=j,xx=0,yy=0;
if(v[i][0]>v[j][0])
{
x=j;
y=i;
}
while(true)
{
while(yy<v[y].size()&&v[y][yy]<v[x][xx])//第一次时少加一个
yy++;
if(yy==v[y].size())
break;
sam++;
while(xx<v[x].size()&&v[x][xx]<v[y][yy])
xx++;
if(xx==v[x].size())
break;
sam++;
}
ans=max(ans,sam);
}
}
printf("%d\n",ans+1);
return 0;
}