#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int num = 0;
  char ch = getchar();
  while (!isdigit(ch)) ch = getchar();
  while (isdigit(ch)) num *= 10, num += ch - 48, ch = getchar();
  return num;
}
int a[1000003];
int tree[2000003];
void add(int l, int r, int x, int i, int t) {
  if (l == r) {
    tree[i] = max(tree[i], t);
    return;
  }
  int mid = (l + r) / 2;
  if (mid > x)
    add(l, mid, x, i << 1, t);
  else
    add(mid + 1, r, x, (i << 1) + 1, t);
  tree[i] = max(tree[(i << 1)], tree[(i << 1) + 1]);
}
int query(int l, int r, int L, int R, int i) {
  if (L <= l && r <= R) return tree[i];
  if (R < l || L > r) return 0;
  int mid = (l + r) / 2;
  return max(query(l, mid, L, R, i << 1),
             query(mid + 1, r, L, R, (i << 1) + 1));
}
signed main() {
  int n = read(), k = read();
  for (int i = 1; i <= n; i++) a[i] = read();
  for (int i = 1; i <= n; i++)
    add(1, 300000, a[i], 1,
        query(0, 300000, max(0, a[i] - k), min(300000, a[i] + k), 1) + 1);
  printf("%d\n", query(0, 300000, 0, 300000, 1));
  return 0;
}
