#include <bits/stdc++.h>
using namespace std;
int count(int arr[], int n, int K) {
  int result = 0;
  int i = 0, j = 0;
  int l = 0;
  int r = 0;
  sort(arr, arr + n);
  for (i = 0; i < n; i++) {
    while (j < n && arr[j] <= arr[i] + K) j++;
    if (result < (j - i)) {
      result = (j - i);
      l = i;
      r = j;
    }
  }
  return result;
}
int main() {
  int n, k;
  cin >> n >> k;
  int arr[n];
  for (int i = 0; i < n; i++) cin >> arr[i];
  cout << count(arr, n, k) + 2 << endl;
}
