#include <bits/stdc++.h>
using namespace std;
long long n, m, k;
long long a[300001], dp[300001], ls[300001], ma;
signed main() {
  long long i, j;
  cin >> n >> k;
  for (i = 1; i <= n; ++i) {
    cin >> a[i];
    for (j = max(0ll, a[i] - k); j <= min(300000ll, a[i] + k); ++j) {
      dp[i] = max(dp[i], dp[ls[j]] + 1);
      ma = max(ma, dp[i]);
    }
    ls[a[i]] = i;
  }
  cout << ma;
}
