#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <typename T>
void print_vec(const vector<T>& v, bool is_reverse = false, ll num = 0) {
  if (num == 0) num = (ll)v.size();
  cout << endl;
  cout << "i=  ";
  for (ll i = 0; i < num; i++) cout << i << "   ";
  cout << endl;
  cout << "    ";
  if (is_reverse)
    for (ll i = num - 1; i >= 0; i--) {
      cout << v[i];
      if (i != 0) cout << "   ";
    }
  else
    for (ll i = 0; i < num; i++) {
      cout << v[i];
      if (i != num - 1) cout << "   ";
    }
  cout << endl;
}
template <typename T>
void print_pairvec(const T& _pair, ll num = 0) {
  cout << endl;
  for (pair<ll, int> x : _pair) {
    cout << x.first << " " << x.second << endl;
  }
}
template <typename T>
void print_vec2(const vector<vector<T>>& v) {
  cout << endl;
  cout << "       ";
  for (ll i = 0; i < v[0].size(); i++) cout << i << "   ";
  cout << endl;
  for (ll i = 0; i < v.size(); i++) {
    cout << "i=" << i << ":   ";
    for (ll j = 0; j < v[i].size(); j++) {
      if (v[i][j] == 0)
        cout << "\x1B[0m" << v[i][j] << "   ";
      else
        cout << "\x1B[31m" << v[i][j] << "   ";
    }
    cout << "\x1B[0m" << endl;
  }
}
int main() {
  ll n, k;
  cin >> n >> k;
  vector<ll> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  const ll MAX = 3e5 + 10;
  vector<ll> vec(MAX, 0);
  for (int i = 0; i < n; i++) {
    ll tmp = vec[a[i]];
    for (int j = a[i] - k; j <= a[i] + k; j++) {
      if (j >= MAX) continue;
      if (j < 0) continue;
      tmp = max(tmp, vec[j] + 1);
    }
    vec[a[i]] = tmp;
  }
  ll ans = 0;
  for (int i = 0; i < (int)vec.size(); i++) ans = max(ans, vec[i]);
  cout << ans << endl;
  return 0;
  return 0;
}
