#include <bits/stdc++.h>
using namespace std;
long long a[300005];
long long vis[300005];
long long n, k;
long long t[6000055];
void modify(long long p, long long value) {
  for (t[p += n] = value; p > 1; p /= 2) t[p / 2] = max(t[p], t[p ^ 1]);
}
long long query(long long l, long long r) {
  long long res = INT_MIN;
  for (l += n, r += n; l < r; l /= 2, r /= 2) {
    if (l & 1) res = max(res, t[l++]);
    if (r & 1) res = max(res, t[--r]);
  }
  return res;
}
long long go() {
  vector<long long> dp(600005, -1);
  long long mini = *min_element(a, a + n);
  long long maxi = *max_element(a, a + n);
  for (long long i = 0; i < n; i++) {
    long long curr = a[i];
    long long lower = max(mini, curr - k);
    int upper = min(maxi, curr + k);
    dp[i] = max(dp[i], query(lower, upper + 1) + 1);
    modify(curr, max(dp[i], query(curr, curr + 1)));
  }
  long long ans = 0;
  for (long long i : dp) ans = max(i, ans);
  return ans;
}
void solve() {
  std::ios::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t;
  t = 1;
  while (t--) {
    cin >> n >> k;
    for (int i = 0; i < n; i++) cin >> a[i];
    long long res = go();
    cout << res;
  }
}
int main() {
  std::ios::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  solve();
}
