#include <bits/stdc++.h>
using namespace std;
const long long maxn = 300000;
long long tree[4 * maxn + 20];
long long query(long long node, long long st, long long en, long long le,
                long long re) {
  if (st == le && en == re) return tree[node];
  long long mid = (st + en) / 2;
  if (re <= mid)
    return query(2 * node, st, mid, le, re);
  else if (le > mid)
    return query(2 * node + 1, mid + 1, en, le, re);
  else
    return max(query(2 * node, st, mid, le, mid),
               query(2 * node + 1, mid + 1, en, mid + 1, re));
}
void update(long long node, long long st, long long en, long long idx,
            long long val) {
  if (st == en) {
    tree[node] = val;
  } else {
    long long mid = (st + en) / 2;
    if (idx <= mid)
      update(2 * node, st, mid, idx, val);
    else
      update(2 * node + 1, mid + 1, en, idx, val);
    tree[node] = max(tree[2 * node], tree[2 * node + 1]);
  }
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(0);
  ;
  long long n, k, i, j;
  cin >> n >> k;
  for (i = 0; i < n; i++) {
    long long x;
    cin >> x;
    long long pmi = max(0LL, x - k);
    long long pma = min(maxn, x + k);
    long long num = query(1LL, 0LL, maxn, pmi, pma + 1);
    update(1LL, 0LL, maxn, x, num + 1);
  }
  long long ans = query(1LL, 0LL, maxn, 0LL, maxn);
  cout << ans;
}
