#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n, k;
  cin >> n >> k;
  int arr[n];
  for (int i = 0; i < n; i++) cin >> arr[i];
  vector<int> dp(n, 0);
  int max_length[300001] = {0};
  for (int i = 0; i < n; i++) {
    int curr = arr[i];
    int lower = max(0, curr - k);
    int upper = min(300001, curr + k);
    for (int j = lower; j < upper + 1; j++) {
      dp[i] = max(dp[i], max_length[j] + 1);
    }
    max_length[curr] = max(dp[i], max_length[curr]);
  }
  int ans = 0;
  for (int i : dp) ans = max(i, ans);
  cout << ans << "\n";
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  t = 1;
  for (int I = 1; I <= t; I++) {
    solve();
  }
  return 0;
}
