#include <bits/stdc++.h>
using namespace std;
const int inf = 1000000000;
const int mod = 1000000007;
const int nil = -1;
long long int i, j, n, m, k, maxi, ans;
long long int a[300000];
long long int maxfromhere[300000];
set<pair<long long int, long long int>> s;
int main() {
  scanf(" %lld %lld", &n, &k);
  for (i = 0; i < n; i++) {
    scanf(" %lld", &a[i]);
    maxfromhere[i] = 1;
  }
  maxi = 1;
  maxfromhere[n - 1] = 1;
  for (i = n - 2; i >= 0; i--) {
    s.insert(make_pair(a[i + 1], -maxfromhere[i + 1]));
    for (j = a[i] - k; j <= a[i] + k; j++) {
      auto it = s.lower_bound(make_pair(j, -n));
      if (it->second != 0)
        maxfromhere[i] = max(maxfromhere[i], -(it->second) + 1);
    }
    if (maxfromhere[i] >= maxi) maxi = maxfromhere[i];
  }
  printf("%lld\n", maxi);
}
