#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll mod_pow(ll a, ll b, ll m) {
  ll res = 1;
  while (b) {
    if (b & 1) {
      res = (res * a) % m;
    }
    a = (a * a) % m;
    b >>= 1;
  }
  return res;
}
ll mod_inverse(long long int a, long long int m) {
  return mod_pow(a, m - 2, m);
}
const long long int maxn = 3e5 + 5;
long long int a[maxn];
long long int tree[6 * maxn];
long long int query(long long int v, long long int l, long long int r,
                    long long int lq, long long int rq) {
  if (lq <= l && r <= rq) {
    return tree[v];
  }
  if (l > rq or lq > r) {
    return 0;
  }
  long long int mid = (l + r) / 2;
  long long int t1 = query(2 * v + 1, l, mid, lq, rq);
  long long int t2 = query(2 * v + 2, mid + 1, r, lq, rq);
  return max(t1, t2);
}
void update(long long int v, long long int pos, long long int l,
            long long int r, long long int val) {
  if (l == r) {
    tree[v] = val;
    return;
  }
  long long int mid = (l + r) / 2;
  if (pos <= mid) {
    update(2 * v + 1, pos, l, mid, val);
  } else {
    update(2 * v + 2, pos, mid + 1, r, val);
  }
  tree[v] = max(tree[2 * v + 1], tree[2 * v + 2]);
}
void solve() {
  long long int n, k;
  cin >> n >> k;
  for (long long int i = 1; i <= n; ++i) {
    cin >> a[i];
  }
  long long int mx = 1;
  for (long long int i = 1; i <= n; ++i) {
    long long int t1 =
        query(1, 1, 3e5, max(1LL, a[i] - k), min((ll)3e5, a[i] + k));
    long long int t2 = query(1, 1, 3e5, a[i], a[i]);
    if (t2 < t1 + 1) {
      update(1, a[i], 1, maxn, t1 + 1);
      mx = max(mx, t1 + 1);
    }
  }
  cout << mx;
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
