#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const long long INF = 1LL << 60;
using vll = vector<long long>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using vc = vector<char>;
using vvc = vector<vc>;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
long long dx[4] = {0, 1, 0, -1};
long long dy[4] = {1, 0, -1, 0};
template <typename T>
struct RMQ {
  int n;
  vector<T> dat;
  RMQ(int n_) : n(), dat(n_ * 4, 0) {
    int x = 1;
    while (n_ > x) {
      x *= 2;
    }
    n = x;
  }
  void update(int i, T x) {
    i += n - 1;
    dat[i] = x;
    while (i > 0) {
      i = (i - 1) / 2;
      dat[i] = max(dat[i * 2 + 1], dat[i * 2 + 2]);
    }
  }
  T query(int a, int b) { return query_sub(a, b, 0, 0, n); }
  T query_sub(int a, int b, int k, int l, int r) {
    if (r <= a || b <= l) {
      return 0;
    } else if (a <= l && r <= b) {
      return dat[k];
    } else {
      T vl = query_sub(a, b, k * 2 + 1, l, (l + r) / 2);
      T vr = query_sub(a, b, k * 2 + 2, (l + r) / 2, r);
      return max(vl, vr);
    }
  }
};
int main() {
  long long n, k;
  cin >> n >> k;
  vll a(n);
  for (long long i = 0; i < (n); i++) cin >> a[i];
  RMQ<long long> s(300001);
  vll dp(n, 1);
  for (long long i = 0; i < (n); i++) {
    long long ma = max(0LL, a[i] - k);
    long long mma = min(300000LL, a[i] + k + 1LL);
    if (dp[i] < s.query(ma, mma) + 1) {
      dp[i] = s.query(ma, mma) + 1;
    }
    if (s.query(a[i], a[i] + 1) < dp[i]) {
      s.update(a[i], dp[i]);
    }
  }
  long long ans = 0;
  for (long long i = 0; i < (n); i++) {
    chmax(ans, dp[i]);
  }
  cout << (ans) << "\n";
}
