#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long n, k;
  cin >> n >> k;
  vector<long long> a(n);
  for (auto &i : a) cin >> i;
  vector<long long> dp(n);
  set<pair<long long, long long>> st;
  for (int i = 0; i < n; i++) {
    dp[i] = 1;
    long long m = -1;
    for (auto j = st.lower_bound({a[i] - k, 0});
         j != st.end() and abs(j->first - a[i]) <= k; j++) {
      dp[i] = max(dp[i], j->second + 1);
      if (a[i] == j->first) m = max(m, max(dp[i], j->second));
    }
    if (m != -1)
      st.insert({a[i], m});
    else
      st.insert({a[i], dp[i]});
  }
  long long m = 0;
  for (int i = 0; i < n; i++) m = max(m, dp[i]);
  cout << m;
  return 0;
}
