#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> v(300001);
  vector<int> v2(300001);
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    if (a - k < 0) {
      v.at(0)++;
    } else {
      v.at(a - k)++;
    }
    if (a + k > 300000) {
    } else {
      v.at(a + k)--;
    }
  }
  int now{}, ans{};
  for (int i = 0; i <= 300000; i++) {
    now += v.at(i);
    ans = max(ans, now);
  }
  cout << ans << endl;
}
