#include<bits/stdc++.h>
using namespace std;//
int n,a[100005],ans=0;
struct lyf{
int m;
int r;
lyf(int x,int y)
{
m=x;
r=y;
}
};
deque<lyf> q;
int main(){
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>a[i];
}
sort(a+1,a+n+1);
q.push_front(lyf(a[1],1));
for(int i=2;i<=n;i++)
{
if(!q.empty())
{
while(q.front().m<a[i]-1&&!q.empty())
{
ans=max(ans,q.front().r);
q.pop_front();
}
if(q.front().m==a[i])
{
q.push_front(lyf(a[i],1));
}
if(q.front().m==a[i]-1)
{
int num=q.front().r;
q.pop_front();
q.push_back(lyf(a[i],num+1));
}
}
}
cout<<ans;
}