#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int N = 3e5 + 10;
int v[N];
int maps[N];
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> v[i];
    maps[v[i]]++;
  }
  if (!k) {
    int ans = 0;
    for (int i = 0; i < N; i++) {
      ans = max(ans, maps[i]);
    }
    cout << ans << "\n";
    return 0;
  }
  vector<int> dp(n + 1, 0);
  queue<int> q;
  dp[0] = 1;
  q.push(0);
  for (int i = 1; i < n; i++) {
    while (!q.empty() and abs(v[i] - v[q.front()]) <= k) {
      dp[i] = max(dp[i], 1 + dp[q.front()]);
      q.pop();
    }
    q.push(i);
  }
  cout << *max_element(dp.begin(), dp.end());
  return 0;
}
