#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long num = 0, neg = 1;
  char c = getchar();
  while (!isdigit(c)) {
    if (c == '-') neg = -1;
    c = getchar();
  }
  while (isdigit(c)) {
    num = (num << 3) + (num << 1) + c - '0';
    c = getchar();
  }
  return num * neg;
}
int n, k, tree[300010 << 2], a[300010], f[300010];
inline void push_up(int x) { tree[x] = max(tree[x << 1], tree[x << 1 | 1]); }
inline void update(int u, int l, int r, int x, int k) {
  if (l == r) {
    tree[x] = max(tree[x], k);
    return;
  }
  int mid = l + r >> 1;
  if (u <= mid)
    update(u, l, mid, x << 1, k);
  else
    update(u, mid + 1, r, x << 1 | 1, k);
  push_up(x);
  return;
}
inline int query(int ql, int qr, int l, int r, int x) {
  if (ql <= l && qr >= r) return tree[x];
  int mid = l + r >> 1, res = 0;
  if (ql <= mid) res = max(res, query(ql, qr, l, mid, x << 1));
  if (qr > mid) res = max(res, query(ql, qr, mid + 1, r, x << 1 | 1));
  return res;
}
int main() {
  n = read(), k = read();
  for (int i = 1; i <= n; i++) a[i] = read();
  for (int i = 1; i <= n; i++) {
    f[i] = query(max(a[i] - k, 0), min(300000, a[i] + k), 1, n, 1) + 1;
    update(a[i], 1, n, 1, f[i]);
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) ans = max(f[i], ans);
  cout << ans;
  return 0;
}
