#include <bits/stdc++.h>
struct segtree {
  int l;
  int r;
  int max;
} tree[300010 * 4];
int dp[300010];
int seq[300010];
int modify(int i, int dis, int val) {
  if (tree[i].l == tree[i].r) {
    tree[i].max = val;
    return 0;
  }
  int mid = (tree[i].l + tree[i].r) >> 1;
  if (dis > mid)
    modify(2 * i + 1, dis, val);
  else
    modify(2 * i, dis, val);
  if (tree[i].max < val) tree[i].max = val;
  return 0;
}
int search(int i, int l, int r) {
  if (tree[i].l >= l && tree[i].r <= r)
    return tree[i].max;
  else if (tree[i].l > r || tree[i].r < l)
    return 0;
  else
    return (((search(2 * i, l, r)) > (search(2 * i + 1, l, r)))
                ? (search(2 * i, l, r))
                : (search(2 * i + 1, l, r)));
}
int build(int i, int l, int r) {
  tree[i].l = l;
  tree[i].r = r;
  tree[i].max = 0;
  if (l == r) return 0;
  int mid = (l + r) >> 1;
  build(2 * i, l, mid);
  build(2 * i + 1, mid + 1, r);
  return 0;
}
int main() {
  int N, K;
  scanf("%d", &N);
  scanf("%d", &K);
  for (int i = 0; i < N; i++) scanf("%d", &seq[i]);
  build(1, 0, 300000);
  dp[0] = 1;
  modify(1, seq[0], dp[0]);
  int res = 0;
  for (int i = 1; i < N; i++) {
    dp[i] = search(1, seq[i] - K, seq[i] + K) + 1;
    modify(1, seq[i], dp[i]);
    if (dp[i] > res) res = dp[i];
  }
  printf("%d", res);
}
