#include <bits/stdc++.h>
using namespace std;
int tree[1000000];
int n;
void update(int l, int v) {
  tree[l + n] = v;
  for (int i = l + n; i > 0; i >>= 1) {
    tree[i >> 1] = max(tree[i], tree[i ^ 1]);
  }
}
int query(int l, int r) {
  int res = 0;
  for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
    if (l & 1) res = max(res, tree[l++]);
    if (r & 1) res = max(res, tree[--r]);
  }
  return res;
}
int main() {
  int k;
  cin >> n >> k;
  int a[n];
  for (int i = 0; i < n; i++) cin >> a[i];
  memset(tree, 0, sizeof(tree));
  for (auto i : a) {
    int c = query(max(0, i - k), min(i + k, 300000) + 1);
    update(i, c + 1);
  }
  cout << query(0, n);
}
