#include<bits/stdc++.h>
using namespace std;
int max1(int num[],int st,int ed)
{
	int maxn=st;
	for(int i=st+1;i<ed;i++){
		if(num[i] > num[maxn]) maxn = i;
	}
	return num[maxn];
}
int min1(int num[],int st,int ed)
{
	int minn=st;
	for(int i=st+1;i<ed;i++){
		if(num[i] < num[minn]) minn = i;
	}
	return num[minn];
}
int main()
{
	int n;
	cin >> n;
	int a[n+5],b[n+5],c[n+5];
	for(int i=0;i<n;i++){
		cin >> a[i];
		b[i]=a[i]+1;
		c[i]=a[i]-1;
	}
	
	int l=n;
	int max=max1(a,0,l);
	max = max1(b,0,l) > max ?max1(b,0,l):max;
	max = max1(c,0,l) > max ?max1(c,0,l):max;
	
	int min=min1(a,0,l);
	min = min1(b,0,l) < min ?min1(b,0,l):min;
	min = min1(c,0,l) < min ?min1(c,0,l):min;
	int p[100005];
	for(int i=min;i<=max;i++){
		for(int j=0;j<n;j++){
			if(a[j] == i) p[i+1]++;
			if(b[j] == i) p[i+1]++;
			if(c[j] == i) p[i+1]++;
		}
		
	}
	int t=max1(p,min+1,max+2);
	cout << t << endl;
	return 0;
}