#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, k, ct = 1;
  cin >> n >> k;
  long long int a[n], b[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    b[i] = 1;
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < i; j++) {
      if (a[j] >= a[i] - k && a[j] <= a[i] + k) b[i] = max(b[i], b[j] + 1);
    }
    ct = max(ct, b[i]);
  }
  cout << ct;
  return 0;
}
