#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
void solve() {
  int n, k;
  cin >> n >> k;
  int ar[n];
  for (int i = 0; i < n; i++) cin >> ar[i];
  int dp[n];
  memset(dp, 0, sizeof(dp));
  for (int i = 0; i < n; i++) {
    dp[i] = 1;
    for (int j = 0; j < i; j++) {
      if (abs(ar[j] - ar[i]) <= k) dp[i] = max(dp[j] + 1, dp[i]);
    }
  }
  cout << *max_element(dp, dp + n) << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  solve();
  return 0;
}
