#include <bits/stdc++.h>
using namespace std;
int n, k, ans = 0, x;
int a[300005], f[3000005];
void update(int id, int l, int r, int i, int val) {
  if (l == r) {
    f[id] = max(f[n], val);
  } else {
    int mid = (l + r) / 2;
    if (i <= mid)
      update(2 * id, l, mid, i, val);
    else
      update(2 * id + 1, mid + 1, r, i, val);
    f[id] = max(f[2 * id], f[2 * id + 1]);
  }
}
int query(int id, int l, int r, int u, int v) {
  if (u > r || v < l) return 0;
  if (u <= l && v >= r) return f[id];
  int mid = (l + r) / 2;
  return max(query(2 * id, l, mid, u, v), query(2 * id + 1, mid + 1, r, u, v));
}
int dp[300005];
int main() {
  cin >> n >> k;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    dp[i] = query(1, 0, 300000, max(0, a[i] - k), min(300000, a[i] + k)) + 1;
    update(1, 0, 300000, a[i], dp[i]);
    ans = max(ans, dp[i]);
  }
  cout << ans;
  return 0;
}
