#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  long long n, k;
  cin >> n >> k;
  long long arr[n];
  for (long long i = 0; i < n; i++) cin >> arr[i];
  map<long long, long long> mp;
  long long res = 1;
  long long mx = *max_element(arr, arr + n);
  for (long long i = 0; i < n; i++) {
    long long ans = 1;
    for (long long j = max((long long)0, arr[i] - k); j <= min(mx, arr[i] + k);
         j++) {
      if (mp.find(j) != mp.end()) ans = max(ans, mp[j] + 1);
    }
    mp[arr[i]] = ans;
    res = max(res, mp[arr[i]]);
  }
  cout << res << "\n";
}
