#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n = 0;
  cin >> n;
  long long int arr[n];
  for (long long int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  sort(arr, arr + n);
  long long int j = 1;
  long long int max = 0;
  long long int x = 0;
  long long int count = 1;
  long long int t = 0;
  long long int k = 0;
  while (j < n) {
    if ((arr[j] - arr[x]) <= 5) {
      j++;
    } else {
      count = (j - x);
      if (max <= count) {
        max = count;
      }
      x = x + 1;
    }
  }
  if ((j - x) > max) {
    cout << (j - x);
  } else {
    cout << max;
  }
}
