#include <bits/stdc++.h>
using namespace std;
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 = 1; i < n; i++) {
    for (int j = 0; j < i; j++) {
      if (abs(v[i] - v[j]) <= k and dp[i] < dp[j] + 1) {
        dp[i] = dp[j] + 1;
      }
    }
  }
  int m = 0;
  for (int i = 0; i < n; i++) {
    m = max(m, dp[i]);
  }
  cout << m << endl;
  return 0;
}
