#include <bits/stdc++.h>
using namespace std;
long long segmTree[300005 * 4], l[300005 * 4], r[300005 * 4], leaves[300005];
void init(size_t nd) {
  if (nd == 0)
    l[0] = 0, r[0] = 300005 - 1;
  else {
    if (nd & 1)
      l[nd] = l[nd / 2], r[nd] = (l[nd / 2] + r[nd / 2]) / 2;
    else
      l[nd] = r[nd - 1] + 1, r[nd] = r[nd / 2 - 1];
  }
  if (l[nd] == r[nd])
    leaves[l[nd]] = nd;
  else {
    init(nd * 2 + 1);
    init(nd * 2 + 2);
  }
}
void upd(size_t p, long long x) {
  long long nd = leaves[x];
  if (segmTree[nd] >= x) return;
  segmTree[nd] = x;
  do {
    nd = (nd - 1) / 2;
    segmTree[nd] = max(segmTree[nd] * 2 + 1, segmTree[nd] * 2 + 2);
  } while (nd > 0);
}
long long query(long long L, long long R) {
  long long ans = 0;
  while (L <= R) {
    long long nd = leaves[L];
    while (nd > 0 && l[(nd - 1) / 2] >= L && r[(nd - 1) / 2] <= R)
      nd = (nd - 1) / 2;
    ans = max(ans, segmTree[nd]);
    L = r[nd] + 1;
  }
  return ans;
}
long long dp[300005], v[300005];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  init(0);
  long long n, k, ans = 0;
  cin >> n >> k;
  for (long long i = 0; i < n; i++) cin >> v[i];
  for (long long i = n - 1; i >= 0; i--) {
    dp[i] = query(max(0ll, v[i] - k), v[i] + k) + 1;
    upd(v[i], dp[i]);
    ans = max(ans, dp[i]);
  }
  cout << ans;
  return 0;
}
