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