#include <bits/stdc++.h>
using namespace std;
void print_arr(int a[], int n) {
  for (int i = 0; i < n; i++) {
    cout << a[i] << " ";
  }
  cout << "\n";
}
void print_arr(long long int a[], int n) {
  for (int i = 0; i < n; i++) {
    cout << a[i] << " ";
  }
  cout << "\n";
}
void init(int a[], int n) {
  for (int i = 0; i < n; i++) a[i] = 0;
}
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> v(n);
  for (int i = 0; i < n; i++) cin >> v[i];
  vector<int> dp(n, -1);
  for (int i = n - 1; i > -1; i--) {
    int f = 1;
    for (int j = i + 1; j < n; j++) {
      if (abs(v[i] - v[j]) <= k) {
        f = max(f, 1 + dp[j]);
      }
    }
    dp[i] = f;
  }
  cout << dp[0] << "\n";
  return 0;
}
