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