#include <bits/stdc++.h>
using namespace std;
long long dp[300001], l_max[300001];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long i, j, k, n, m;
  cin >> n >> m;
  long long a[n + 1];
  for (i = 0; i < n; i++) cin >> a[i];
  for (i = 0; i < n; i++) {
    long long cur = a[i];
    long long low = max(0ll, a[i] - m);
    long long high = min(300000ll, a[i] + m);
    for (j = low; j <= high; j++) {
      dp[i] = max(dp[i], l_max[j] + 1);
    }
    l_max[cur] = dp[i];
  }
  long long an = 0;
  for (i = 0; i < n; i++) {
    an = max(an, dp[i]);
  }
  cout << an << "\n";
  return 0;
}
