#include <bits/stdc++.h>
using namespace std;
int tr[4 * 300000 + 2], a[300000 + 2];
void update(int pos, int st, int ed, int x, int val) {
  if (st == ed && st == x) {
    tr[pos] = max(tr[pos], val);
    return;
  }
  int mid = st + ((ed - st) >> 1);
  if (x <= mid)
    update(2 * pos, st, mid, x, val);
  else
    update(2 * pos + 1, mid + 1, ed, x, val);
  tr[pos] = max(tr[2 * pos], tr[2 * pos + 1]);
}
int query(int pos, int st, int ed, int l, int r) {
  if (st > r || ed < l) return 0;
  if (st >= l && ed <= r) {
    return tr[pos];
  }
  int mid = st + ((ed - st) >> 1);
  return max(query(2 * pos, st, mid, l, r),
             query(2 * pos + 1, mid + 1, ed, l, r));
}
int main() {
  int n, k;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (int i = 1; i <= n; i++) {
    int l = max(0, a[i] - k);
    int r = min(300000, a[i] + k);
    int p = query(1, 1, 300000, l, r);
    update(1, 1, 300000, a[i], p + 1);
  }
  cout << query(1, 1, 300000, 1, 300000) << "\n";
  return 0;
}
