#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr int MAX_N = 300000;
int node[4 * MAX_N], segtree_size;
void segtree_init(int n) {
  segtree_size = 1;
  while (segtree_size < n) segtree_size *= 2;
  for (int i = 0; i < 2 * segtree_size - 1; ++i) node[i] = 0;
}
void segtree_update(int a, int x) {
  a += segtree_size - 1;
  node[a] = x;
  while (a > 0) {
    a = (a - 1) / 2;
    node[a] = max(node[2 * a + 1], node[2 * a + 2]);
  }
}
int segtree_query(int a, int b, int k = 0, int l = 0, int r = segtree_size) {
  if (b <= l || r <= a) return 0;
  if (a <= l && r <= b) return node[k];
  int vl = segtree_query(a, b, 2 * k + 1, l, (l + r) / 2);
  int vr = segtree_query(a, b, 2 * k + 2, (l + r) / 2, r);
  return max(vl, vr);
}
int main() {
  int n, k;
  cin >> n >> k;
  segtree_init(n);
  for (int i = 0; i < n; ++i) {
    int a;
    cin >> a;
    int l = segtree_query(a - k, a + k + 1);
    segtree_update(a, l + 1);
  }
  cout << segtree_query(0, n);
  return 0;
}
