#include <bits/stdc++.h>
using namespace std;
const long long INF = 1 << 29;
const long long LLINF = (1LL << 60LL);
const long long MOD = 1000000007;
const long long MAX_V = 500;
const long long mod = 998244353;
const long long MAX = 2100000;
const double pi = acos(-1);
const double eps = 1e-10;
long long dx[8] = {1, 0, -1, 0, 1, -1, 1, -1};
long long dy[8] = {0, 1, 0, -1, 1, -1, -1, 1};
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
struct SegmentTree {
  long long n;
  vector<T> data;
  T def;
  function<T(T, T)> operation;
  function<T(T, T)> update;
  SegmentTree(long long _n, T _def, function<T(T, T)> _operation,
              function<T(T, T)> _update)
      : def(_def), operation(_operation), update(_update) {
    n = 1;
    while (n < _n) {
      n *= 2;
    }
    data = vector<T>(2 * n - 1, def);
  }
  void change(long long i, T x) {
    i += n - 1;
    data[i] = update(data[i], x);
    while (i > 0) {
      i = (i - 1) / 2;
      data[i] = operation(data[i * 2 + 1], data[i * 2 + 2]);
    }
  }
  T _query(long long a, long long b, long long k, long long l, long long r) {
    if (r <= a || b <= l) return def;
    if (a <= l && r <= b) {
      return data[k];
    } else {
      T vl = _query(a, b, 2 * k + 1, l, (l + r) / 2);
      T vr = _query(a, b, 2 * k + 2, (l + r) / 2, r);
      return operation(vr, vl);
    }
  }
  T query(long long a, long long b) { return _query(a, b, 0, 0, n); }
  T operator[](long long i) { return data[i + n - 1]; }
  void print() {
    for (long long i = 0; i < 10; i++) {
      cout << data[i + n - 1] << " ";
    }
    cout << endl;
  }
};
void solve() {
  long long a[300010];
  long long n;
  cin >> n;
  long long k;
  cin >> k;
  for (long long i = 0; i < n; i++) cin >> a[i];
  long long ex = 0;
  auto fx = [](long long a, long long b) { return max(a, b); };
  auto update = [](long long a, long long b) { return b; };
  SegmentTree<long long> sg(300010, ex, fx, update);
  long long len = 1;
  long long ans = 1;
  long long now = a[0];
  for (long long i = 0; i < n; i++) {
    long long l = max(0ll, a[i] - k);
    long long r = min(300000ll, a[i] + k);
    long long sum = sg.query(l, r + 1);
    sg.change(a[i], sum + 1);
  }
  for (long long i = 0; i < n; i++) {
    chmax(ans, sg[i]);
  }
  cout << ans << endl;
}
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  long long t = 1;
  for (long long i = 0; i < t; i++) {
    solve();
  }
  return 0;
}
