#include <bits/stdc++.h>
using namespace std;
const long long mod = 998244353;
long double PI = acosl(-1);
const long long infl = 1e18;
const int inf = 2e9;
const int nmax = 3e5 + 5;
const int MAXLG = log2(nmax) + 1;
const int N = nmax;
int tree[4 * N], a[N];
void build(int cn, int b, int e) {
  if (b == e) {
    tree[cn] = a[b];
    return;
  }
  int lc = 2 * cn, rc = lc + 1, mid = (b + e) / 2;
  build(lc, b, mid);
  build(rc, mid + 1, e);
  tree[cn] = max(tree[lc], tree[rc]);
}
void upd(int cn, int b, int e, int i, int add) {
  if (b > i or e < i) {
    return;
  }
  int lc = 2 * cn, rc = lc + 1, mid = (b + e) / 2;
  if (b >= i and e <= i) {
    tree[cn] = add;
    return;
  }
  upd(lc, b, mid, i, add);
  upd(rc, mid + 1, e, i, add);
  tree[cn] = max(tree[lc], tree[rc]);
}
int query(int cn, int b, int e, int i, int j) {
  if (b > j or e < i) return -inf;
  if (b >= i and e <= j) {
    return tree[cn];
  }
  int lc = 2 * cn, rc = lc + 1, mid = (b + e) / 2;
  return max(query(lc, b, mid, i, j), query(rc, mid + 1, e, i, j));
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int lim = 300000;
  int n, k;
  cin >> n >> k;
  vector<int> v(n);
  for (int &x : v) cin >> x;
  for (int x : v) {
    int bam = max(1, x - k), dan = min(lim, x + k);
    int boro = query(1, 1, lim, bam, dan);
    upd(1, 1, lim, x, boro + 1);
  }
  cout << query(1, 1, lim, 1, lim) << endl;
}
