#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 100;
int T;
int n, k, a[N];
int tree[N * 4];
void change(int i, int l, int r, int pos, int val) {
  if (l == r) {
    tree[i] = val;
    return;
  }
  int mid = l + r >> 1;
  if (pos <= mid)
    change(i << 1, l, mid, pos, val);
  else
    change(i << 1 | 1, mid + 1, r, pos, val);
  tree[i] = max(tree[i << 1], tree[i << 1 | 1]);
}
int ask(int i, int l, int r, int L, int R) {
  if (L <= l && r <= R) {
    return tree[i];
  }
  int mid = l + r >> 1;
  int ans = 0;
  if (L <= mid) ans = max(ans, ask(i << 1, l, mid, L, R));
  if (R > mid) ans = max(ans, ask(i << 1 | 1, mid + 1, r, L, R));
  return ans;
}
int dp[N];
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> k;
  for (int i = 1; i <= n; i++) cin >> a[i], a[i]++;
  int maxx = *max_element(a + 1, a + n + 1);
  dp[1] = 1;
  change(1, 1, 300001, a[1], 1);
  for (int i = 2; i <= n; i++) {
    int ans = ask(1, 1, maxx, max(1, a[i] - k), min(300001, a[i] + k));
    dp[i] = ans + 1;
    change(1, 1, maxx, a[i], dp[i]);
  }
  cout << dp[n];
  return 0;
}
