#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  map<int, int> mp;
  for (long long i = 0; i < (long long)(n); i++) {
    int num;
    cin >> num;
    num--;
    bool isIsolate = true;
    int biggest = 0;
    for (long long i = (max(0, num - k));
         i < (long long)(min(300000, num + k + 1)); i++) {
      if (mp[i] != 0) {
        isIsolate = false;
        biggest = max(biggest, mp[i]);
        mp[i] = 0;
      }
    }
    if (isIsolate) {
      mp[num] = 1;
    } else {
      mp[num] = biggest + 1;
    }
  }
  int biggest = 0;
  for (long long i = 0; i < (long long)(300000); i++)
    biggest = max(biggest, mp[i]);
  cout << biggest << endl;
  return 0;
}
