#include <bits/stdc++.h>
using namespace std;
const long long siz = 3e5 + 10;
const long long SIZ = 3e5 + 10;
const long long mod = 998244353;
const long long maxx = 2e9;
const long long MAXX = 1e18;
const string file = "4";
long long a[siz];
long long seg[4 * siz];
void pos_update(long long id, long long st, long long ed, long long pos,
                long long val) {
  if (st == ed) {
    seg[id] = max(seg[id], val);
    return;
  }
  long long mid = (st + ed) / 2;
  if (pos <= mid) {
    pos_update(2 * id, st, mid, pos, val);
  } else {
    pos_update(2 * id + 1, mid + 1, ed, pos, val);
  }
  seg[id] = max(seg[2 * id], seg[2 * id + 1]);
}
long long range_max(long long id, long long st, long long ed, long long lt,
                    long long rt) {
  if (rt < st || ed < lt) {
    return 0;
  }
  if (lt <= st && ed <= rt) {
    return seg[id];
  }
  long long mid = (st + ed) / 2;
  long long m1 = range_max(2 * id, st, mid, lt, rt);
  long long m2 = range_max(2 * id + 1, mid + 1, ed, lt, rt);
  return max(m1, m2);
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n, k;
  cin >> n >> k;
  for (long long i = 1; i <= n; i++) {
    cin >> a[i];
    a[i]++;
  }
  for (long long i = 1; i <= n; i++) {
    pos_update(1, 1, SIZ, a[i],
               range_max(1, 1, SIZ, max(a[i] - k, 1LL), min(a[i] + k, n)) + 1);
  }
  cout << range_max(1, 1, n, 1, n) << "\n";
  return 0;
}
