#include <iostream>
using namespace std;
const int maxn=1e5+10;
int a[maxn],b[1000000];
int main(int argc, char *argv[])
{
	int n;
	int ave;
	cin>>n; 
	memset(b,0,sizeof(b));
	for(int i=0;i<n;i++){
        cin>>a[i];
        b[a[i]+1]++;
	}
	int max=0;
	for(int i=0;i<n;i++){
		int h=b[a[i]]+b[a[i]+1]+b[a[i]+2];
		  if(h>max)max=h;
	}
	cout<<max<<endl;
	return 0;
}