#include <bits/stdc++.h>
using namespace std;
int n, k, a[300009];
int tree[300009 << 2];
void build(int p, int l, int r) {
  if (l == r) {
    tree[p] = 1;
    return;
  }
  build((p << 1), l, ((l + r) >> 1));
  build(((p << 1) | 1), ((l + r) >> 1) + 1, r);
  tree[p] = max(tree[(p << 1)], tree[((p << 1) | 1)]);
}
void update(int p, int l, int r, int pp, int w) {
  if (pp < l || r < pp) return;
  if (l == r) {
    tree[p] += w;
    return;
  }
  update((p << 1), l, ((l + r) >> 1), pp, w);
  update(((p << 1) | 1), ((l + r) >> 1) + 1, r, pp, w);
  tree[p] = max(tree[(p << 1)], tree[((p << 1) | 1)]);
}
int getmax(int p, int l, int r, int ll, int rr) {
  if (rr < l || r < ll) return -1;
  if (ll <= l && r <= rr) return tree[p];
  return max(getmax((p << 1), l, ((l + r) >> 1), ll, rr),
             getmax(((p << 1) | 1), ((l + r) >> 1) + 1, r, ll, rr));
}
int main() {
  scanf("%d%d", &n, &k);
  int limit = 0, tmp;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    a[i]++;
    limit = max(limit, a[i]);
  }
  update(1, 1, limit, a[1], 1);
  for (int i = 2; i <= n; i++) {
    tmp = 1;
    tmp = max(tmp,
              getmax(1, 1, limit, max(a[i] - k, 1), min(a[i] + k, limit)) + 1);
    update(1, 1, limit, a[i], tmp);
  }
  printf("%d", tree[1]);
  return 0;
}
