#include <bits/stdc++.h>
using namespace std;
const int nm = 300010;
int n, k, a[nm];
int tree[4 * nm];
void update(int u, int x, int l, int r, int id) {
  if (l == r) {
    tree[id] = max(tree[id], x);
    return;
  }
  int m = (l + r) >> 1, c1 = id << 1, c2 = c1 ^ 1;
  if (u <= m) {
    update(u, x, l, m, c1);
  } else {
    update(u, x, m + 1, r, c2);
  }
  tree[id] = max(tree[c1], tree[c2]);
}
int get(int u, int v, int l, int r, int id) {
  if (l >= u && r <= v) {
    return tree[id];
  }
  if (l > v || r < u) {
    return -1;
  }
  int m = (l + r) >> 1, c1 = id << 1, c2 = c1 ^ 1;
  int res = max(get(u, v, l, m, c1), get(u, v, m + 1, r, c2));
  return res;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> k;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    a[i]++;
  }
  int res = 0;
  for (int i = 1; i <= n; ++i) {
    int f = get(max(1, a[i] - k), min(nm - 1, a[i] + k), 1, nm - 1, 1);
    res = max(res, f + 1);
    update(a[i], res, 1, nm - 1, 1);
  }
  cout << res << "\n";
}
