#include <bits/stdc++.h>
using namespace std;
long long pp(long long n, long long k, long long a[]) {
  vector<long long> ash(n, 0);
  long long qq[300001] = {0};
  for (int i = 0; i < n; i++) {
    long long lower = max((long long)0, a[i] - k);
    long long upper = min((long long)300001, a[i] + k);
    for (int j = lower; j < upper + 1; j++) {
      ash[i] = max(ash[i], qq[j] + 1);
    }
    qq[a[i]] = max(ash[i], qq[a[i]]);
  }
  long long ans = 0;
  for (long long i : ash) ans = max(i, ans);
  return ans;
}
int main() {
  long long n, k;
  cin >> n >> k;
  long long a[n];
  for (int i = 0; i < n; i++) cin >> a[i];
  cout << pp(n, k, a);
}
