#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 7;
struct nd {
  int l, r, v, lz;
} seg[maxn << 2];
int n = 3e5 + 50;
inline void pushup(int rt) {
  seg[rt].v = max(seg[rt << 1].v, seg[rt << 1 | 1].v);
}
void pushdown(int rt) {
  if (seg[rt].lz) {
    seg[rt << 1].lz += seg[rt].lz;
    seg[rt << 1 | 1].lz += seg[rt].lz;
    seg[rt << 1].v += seg[rt].lz;
    seg[rt << 1 | 1].v += seg[rt].lz;
    seg[rt].lz = 0;
  }
}
void bulid(int b = 1, int e = n, int rt = 1) {
  seg[rt].l = b;
  seg[rt].r = e;
  if (b == e) {
    seg[rt].v = 0;
    return;
  }
  int m = b + e >> 1;
  bulid(b, m, rt << 1);
  bulid(m + 1, e, rt << 1 | 1);
  pushup(rt);
}
void update(int l, int r, int xx, int b = 1, int e = n, int rt = 1) {
  if (l <= b && e <= r) {
    seg[rt].lz += xx;
    seg[rt].v += xx;
    return;
  }
  pushdown(rt);
  int m = b + e >> 1;
  if (l <= m) update(l, r, xx, b, m, rt << 1);
  if (r > m) update(l, r, xx, m + 1, e, rt << 1 | 1);
  pushup(rt);
}
int query(int l, int r, int b = 1, int e = n, int rt = 1) {
  if (l <= b && e <= r) {
    return seg[rt].v;
  }
  pushdown(rt);
  int m = b + e >> 1;
  int re = 0;
  if (l <= m) re = max(re, query(l, r, b, m, rt << 1));
  if (r > m) re = max(re, query(l, r, m + 1, e, rt << 1 | 1));
  return re;
}
int t, k;
int main() {
  bulid();
  cin >> t >> k;
  int maxx = 0;
  while (t--) {
    int x;
    cin >> x;
    update(max(1, x - k), x + k, 1);
    maxx = max(x + k, maxx);
  }
  cout << query(1, maxx) - 1 << endl;
  return 0;
}
