#include <bits/stdc++.h>
using namespace std;
long long int INF = 1e18;
long long int MOD = 1e9 + 7;
long long int segtree[1200500], pre[300002];
long long int get_max(long long int v, long long int bl, long long int br,
                      long long int ql, long long int qr) {
  if (!(bl <= ql && qr <= br && ql <= qr)) return 0;
  if (bl == ql && br == qr) return segtree[v];
  long long int mid = (bl + br) >> 1;
  long long int l = get_max(2 * v, bl, mid, ql, min(qr, mid));
  long long int r = get_max(2 * v + 1, mid + 1, br, max(ql, mid + 1), qr);
  if (pre[l] > pre[r]) return l;
  return r;
}
void update(long long int v, long long int bl, long long int br,
            long long int pos) {
  if (bl == br) {
    segtree[v] = pos;
    return;
  }
  long long int mid = (bl + br) >> 1;
  if (pos <= mid)
    update(2 * v, bl, mid, pos);
  else
    update(2 * v + 1, mid + 1, br, pos);
  long long int l = segtree[2 * v];
  long long int r = segtree[2 * v + 1];
  if (pre[l] > pre[r])
    segtree[v] = l;
  else
    segtree[v] = r;
}
void solve() {
  long long int n, k;
  cin >> n >> k;
  long long int MAX = 300002;
  long long int arr[n];
  for (long long int i = 0; i < n; i++) {
    cin >> arr[i];
    arr[i]++;
  }
  for (long long int i = 0; i < n; i++) {
    long long int maxx_ind =
        get_max(1, 1, MAX - 1, max(0LL, arr[i] - k), min(arr[i] + k, MAX - 1));
    pre[arr[i]] = pre[maxx_ind] + 1;
    update(1, 1, MAX - 1, arr[i]);
  }
  long long int ans = 0;
  for (long long int i = 0; i < MAX; i++) ans = max(pre[i], ans);
  cout << ans << '\n';
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
