#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> b(300001, 0);
  for (int i = 0; i < (int)(n); i++) {
    int a, x = 0;
    cin >> a;
    for (int j = (max(0, a - k)); j < (int)(min(300000, a + k) + 1); j++)
      if (b.at(j) > x) x = b.at(j);
    b.at(a) = x + 1;
  }
  int ans = 0;
  for (int i = 0; i < (int)(n); i++)
    if (b.at(i) > ans) ans = b.at(i);
  cout << ans << endl;
}
