#include <bits/stdc++.h>
using namespace std;
vector<int> t(300004);
int lis(vector<int> arr, int n, int k) {
  t[0] = 1;
  for (int i = 1; i < n; i++) {
    t[i] = 1;
    for (int j = 0; j < i; j++)
      if (abs(arr[i] - arr[j]) <= k && t[i] < t[j] + 1) t[i] = t[j] + 1;
  }
  return *max_element(t.begin(), t.end());
}
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> v(n);
  for (int i = 0; i < n; i++) cin >> v[i];
  cout << lis(v, n, k);
}
