#include <bits/stdc++.h>
using namespace std;
long maxf(long a, long b) { return a >= b ? a : b; }
long minf(long a, long b) { return a <= b ? a : b; }
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long n, k, i, maxi = 0, data;
  cin >> n >> k;
  vector<long> arr(n), maxlength(300005, 0);
  for (i = 0; i < n; i++) {
    cin >> data;
    maxi = max(data, maxi);
    arr.push_back(data);
  }
  vector<long> dp(maxi + 1, 0);
  for (i = 0; i < n; i++) {
    long lower = maxf(0, arr[i] - k);
    long higher = minf(arr[i] + k, 300000);
    for (int j = lower; j <= higher; ++j) {
      dp[i] = max(dp[i], maxlength[j] + 1);
    }
    maxlength[arr[i]] = max(maxlength[arr[i]], dp[arr[i]]);
  }
  long ans = 0;
  for (auto x : dp) ans = max(ans, x);
  cout << ans << endl;
  return 0;
}
