#include<bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double
#define vll vector<ll>
#define pb push_back
#define f first
#define se second
#define endl '\n'
#define Left Node << 1
#define Right Node << 1 | 1
#define INF -1e9
#define Fast() {ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);}

void solve()
{
    int n;
    cin >> n;

    vector<int> a(n);
    for (int &it : a)
        cin >> it;

    sort(a.begin(), a.end());

    int ans = 1;
    for (int i = 0; i < n; i++) {
        int pos = upper_bound(a.begin(), a.end(), a[i] + 5) - a.begin();
        
        ans = max(ans, pos - i);
    }

    cout << ans << endl;
}

int main()
{
    Fast();

    int t = 1;
    // cin >> t;
    while (t--)
    {
        solve();
    }

    return 0;
}