#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
using namespace std;
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  vector<int> v;
  for (int i(0); i < n; ++i) {
    int x;
    cin >> x;
    v.push_back(x);
  }
  vector<int> dp(n, 1);
  for (int i(0); i < n; ++i) {
    int j = 0;
    while (j < n && (abs(v[j] - v[i]) <= k)) {
      dp[i] = max(dp[i], dp[j] + 1);
      j++;
    }
  }
  int ans = dp[0];
  for (int i(1); i < n; ++i) {
    ans = max(ans, dp[i]);
  }
  cout << ans;
}
