#include <iostream>
#include <vector>
#include <unordered_map> 
#include <algorithm>
#include <math.h>
#include <assert.h>
#include <queue>
#include <set>
#include <string.h>
#include <limits.h>


#define md 1000000007
#define INF 100000000

using namespace std;

typedef long long int ll;

typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<vii> vvii;



unordered_map<ll,ll> Fib;
 
ll fib(ll n)
{
    if(n<2) return 1;
    if(Fib.find(n) != Fib.end()) return Fib[n];
    Fib[n] = (fib((n+1) / 2)*fib(n/2) + fib((n-1) / 2)*fib((n-2) / 2)) % md;
    return Fib[n];
}


void pre_process(string p, int *back_table){
    int i = 0, j = -1, length = p.length();
    back_table[0] = -1;

    while(i <= length) { 
        while(j != -1 && p[i] != p[j]) j = back_table[j];
        i++; j++;
        back_table[i] = j;
    }

}

void _search(string p, string t, int *back_table){
    int i = 0, j = 0, length = t.length(), m = p.length();

    while(i <= length){
        while(j != 0 && t[i] != p[j]) j = back_table[j];
        i++; j++;
        if(j == m) { cout << "Pattern at: " << i - j << endl; j = back_table[j]; }
    }
}

int func(int arr[],int n,int m) {
    int maxsum;
    int incl[n];
    int excl[n];
    incl[0] = arr[0];
    excl [0] = 0;
    for(int i=1;i<n;i++) {
        if(i-m-1 >=0) {
            incl[i] = max(incl[i-m-1],excl[i-m-1]) + arr[i];
        }
        else
            incl[i] = arr[i];
        
        excl[i] = max(excl[i-1],incl[i-1]);
        maxsum = max(maxsum,max(incl[i],excl[i]));
    }

    return maxsum;
}

int show(int x, float y){
    return x + y;
}


int show(int x){ return x; }

float fn_(int x = show(2, 3.3)){
    return x;
}

int fn(int x = show(2)){
    return x;
}

// ll n;
// vvi adjList;
// vi weights;
// vector<bool> visited;
// // vvi dp;

// ll ans;



// bool dfs(ll u, ll v){
//     // if(dp[u][v] != -1) { ans = (ans + dp[u][v]) % md; return true; }

//     if(u == v) { /*cout << u << ' ' << endl;*/ ans += weights[u]; return true; }
//     // cout << u << ' ';
//     visited[u] = true;
    
//     bool x = false;

//     for(uint i = 0; i < adjList[u].size(); i++){
//         if(!visited[adjList[u][i]]){
//             x = dfs(adjList[u][i], v);
//             if(x != false){
//                 // cout << ans << ' ';
//                 // cout << u << ' ' << ans << ' ' << endl;

//                 ans = (ans + weights[u]) % md;
//                 // dp[u][v] = ans;
//             }
//         }
//     }
//     // visited[u] = false;             // Attention needed
//     return x;
// }

// void combinations(int x, int k){
//     if(k == 0){
//         for(int i = 0; i < visited.size(); i++){
//             if(visited[i]) cout << i << " ";
//         }
//         cout << endl;
//         return;
//     }

//     if(x >= visited.size())  return;

//     visited[x] = true;
//     combinations(x + 1, k - 1);
//     visited[x] = false;
//     combinations(x + 1, k);
// }

/*vvi adjList;
vi dfs_num, dfs_parent, articulationVertex, dfs_low;

#define UNVISITED 0
#define EXPLORED 1
#define VISITED 2

int dfsRoot = 0, rootChildren = 0, dfsNumber = 0;

void dfs(int u){
    dfs_num[u] = EXPLORED;
    for(uint i = 0; i < adjList[u].size(); i++){
        if(dfs_num[ adjList[u][i] ] == UNVISITED){
            dfs_parent[ adjList[u][i] ] = u;
            dfs(adjList[u][i]);
        }
        else if(dfs_num[ adjList[u][i] ] == EXPLORED){
            if(dfs_parent[ u ] != adjList[u][i]){
                cout << "Back edge. Forms a cycle: " << u << " , " << adjList[u][i] << endl;
            }
            else cout << "Two ways between " << u << " , " << adjList[u][i] << endl;
        }
        else if(dfs_num[ adjList[u][i] ] == VISITED){
            cout << "Cross edge between " << u << " ,  " << adjList[u][i] << endl;
        }
    }
    dfs_num[u] = VISITED;
}


void articulationPointsAndBridges(int u){
    dfs_num[u] = dfs_low[u] = dfsNumber++;

    for(uint i = 0; i < adjList[u].size(); i++){
        int v = adjList[u][i]; 
        if(dfs_num[v] == UNVISITED){
            dfs_parent[v] = u;
            if(dfsRoot == u){
                rootChildren++;
            }
            articulationPointsAndBridges(v);
            if(dfs_low[v] >= dfs_num[u]){
                articulationVertex[u] = true;
            }
            if(dfs_low[v] > dfs_num[u]){
                cout << "Bridge between the points: " << v << " , " << u << endl;
            }
            dfs_low[u] = min(dfs_low[u], dfs_low[v]);
        }
        else if(dfs_parent[u] != v){
            dfs_low[u] = min(dfs_low[u], dfs_num[v]);
        }
    }
}
*/


void solve() {
    int n;
    cin >> n;
    int a[n];
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    sort(a, a + n);

    int start = 0, end = 0;
    int res = -1;
    while(end < n && start < n){
        while(end < n && a[end] - a[start] <= 2){
            end++;
        }    
        res = max(res, end - start);
        start++;
    }
    cout << res << endl;
}

int main() {
    /*int tt;
    cin >> tt;
    while(tt--){*/
        solve();
    // }

}


// akasakaakas 
// akasakaakas

// akasakaakasaka

// kesav696@sbi
// kesav1096@sbi




Measured memory_bytes: 640