#include <bits/stdc++.h>
using namespace std;
int val = 0;
int binsearch(int l, int r, int arr[]) {
  if (l > r) {
    return -1;
  }
  int mid = (l + r) / 2;
  if (l == r) {
    if (arr[mid] > val) {
      return -1;
    } else {
      return mid;
    }
  }
  if (arr[mid] <= val && arr[mid + 1] <= val) {
    return binsearch(mid + 1, r, arr);
  } else if (arr[mid] <= val && arr[mid + 1] > val) {
    return mid;
  } else if (arr[mid] > val) {
    return binsearch(l, mid - 1, arr);
  }
}
int main() {
  int n;
  cin >> n;
  int i, arr[n];
  for (i = 0; i < n; i++) {
    cin >> arr[i];
  }
  sort(arr, arr + n);
  if (n == 1) {
    cout << 1;
    return 0;
  }
  int max = 0;
  for (i = 0; i < n; i++) {
    val = arr[i] + 5;
    if (val >= arr[n - 1]) {
      if (max < n - i) {
        max = n - i;
      }
      break;
    }
    int k = binsearch(i + 1, n - 1, arr);
    if (k == -1) {
      if (max < 1) {
        max = 1;
      }
    }
    if (max < k - i + 1) {
      max = k - i + 1;
    }
  }
  cout << max;
  return 0;
}
