#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  const int geta = 300300;
  vector<int> ps(600600, 0);
  for (int i = 0; i < n; ++i) {
    int l = a[i] - k, r = a[i] + k;
    ps[geta + l]++;
    ps[geta + r + 1]--;
  }
  for (int i = 0; i + 1 < 600600; ++i) {
    ps[i + 1] += ps[i];
  }
  int ans = 0;
  for (int i = 0; i < 600600; ++i) {
    ans = max(ans, ps[i]);
  }
  cout << ans - 1 << endl;
}
