#include <bits/stdc++.h>
using namespace std;
struct SegmentTree {
  SegmentTree* left;
  SegmentTree* right;
  long long L;
  long long R;
  long long lazy;
  long long maxPos;
  SegmentTree(int l, int r, int k)
      : left(nullptr), right(nullptr), L(l), R(r), maxPos(k) {}
};
void normalize(SegmentTree* root) {
  if (root->L < root->R) {
    if (!root->left || !root->right) {
      int m = root->L + (root->R - root->L) / 2;
      root->left = new SegmentTree(root->L, m, root->maxPos);
      root->right = new SegmentTree(m + 1, root->R, root->maxPos);
    } else if (root->lazy > 0) {
      root->left->maxPos += root->lazy;
      root->left->lazy += root->lazy;
      root->right->maxPos += root->lazy;
      root->right->lazy += root->lazy;
    }
  }
  root->lazy = 0;
}
long long query(SegmentTree* root, int i, int j) {
  if (i > j || !root || root->R < i || root->L > j) return 0;
  if (i <= root->L && j >= root->R) return root->maxPos;
  normalize(root);
  return max(query(root->left, i, j), query(root->right, i, j));
}
void update(SegmentTree* root, int i, int j) {
  if (i > j || !root || i > root->R || j < root->L) return;
  if (i <= root->L && j >= root->R) {
    root->maxPos++;
    root->lazy++;
    return;
  }
  normalize(root);
  update(root->left, i, j);
  update(root->right, i, j);
  root->maxPos = max(root->left->maxPos, root->right->maxPos);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int N, K;
  cin >> N >> K;
  SegmentTree* tree = new SegmentTree(0 - K, 300000 + K, 0);
  for (int i = 0; i < N; i++) {
    int num;
    cin >> num;
    int minBound = num - K;
    int upBound = num + K;
    update(tree, minBound, upBound);
  }
  std::cout << tree->maxPos - 1 << "\n";
  return 0;
}
