#include <bits/stdc++.h>
using namespace std;
const long long mod = 998244353;
const long long N = 3E5 + 1;
long long n, k;
long long a[N], tree[4 * N];
void update(long long node, long long st, long long en, long long idx,
            long long val) {
  if (st == en) {
    tree[node] = val;
    return;
  }
  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]);
}
long long query(long long node, long long st, long long en, long long l,
                long long r) {
  if (l <= 0 || r > N || l > r || st > r || en < l) return 0;
  if (l <= st && en <= r) return tree[node];
  long long mid = (st + en) / 2;
  long long left = query(2 * node, st, mid, l, r);
  long long right = query(2 * node + 1, mid + 1, en, l, r);
  return max(left, right);
}
int32_t main() {
  cin >> n >> k;
  for (long long i = 1; i <= n; i++) {
    cin >> a[i];
    a[i]++;
  }
  for (long long i = 1; i <= n; i++) {
    long long x = a[i];
    long long l = x - k, r = x + k;
    long long mx = query(1, 1, N, l, r);
    update(1, 1, N, x, 1 + mx);
  }
  long long ans = query(1, 1, N, 1, N);
  cout << ans;
  return 0;
}
