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