#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
long long Rand(long long B) { return (unsigned long long)rng() % B; }
const int N = 1e6;
const int INF = 1e9;
struct Seg {
  long long minn[N << 1], maxx[N << 1], sum[N << 1], add[N << 1];
  inline void pushup(long long rt) {
    minn[rt] = min(minn[rt << 1 | 1], minn[rt << 1]);
    maxx[rt] = max(maxx[rt << 1 | 1], maxx[rt << 1]);
    sum[rt] = sum[rt << 1] + sum[rt << 1 | 1];
  }
  inline void pushdown(long long rt, long long l, long long r) {
    if (add[rt]) {
      long long mid = (l + r) >> 1;
      sum[rt << 1] = sum[rt << 1] + add[rt] * (mid - l + 1);
      sum[rt << 1 | 1] = sum[rt << 1 | 1] + add[rt] * (r - mid);
      maxx[rt << 1] = maxx[rt << 1] + add[rt];
      maxx[rt << 1 | 1] = maxx[rt << 1 | 1] + add[rt];
      minn[rt << 1] = minn[rt << 1] + add[rt];
      minn[rt << 1 | 1] = minn[rt << 1 | 1] + add[rt];
      add[rt << 1] += add[rt];
      add[rt << 1 | 1] += add[rt];
      add[rt] = 0;
    }
    return;
  }
  inline void buildtree(long long rt, long long l, long long r) {
    add[rt] = 0;
    if (l == r) {
      minn[rt] = maxx[rt] = sum[rt] = 0;
      return;
    }
    long long mid = (l + r) >> 1;
    buildtree(rt << 1, l, mid);
    buildtree(rt << 1 | 1, mid + 1, r);
    pushup(rt);
  }
  inline void modify(long long rt, long long l, long long r, long long nl,
                     long long nr, long long k) {
    if (nl <= l && r <= nr) {
      add[rt] += k;
      maxx[rt] += k;
      minn[rt] += k;
      sum[rt] += k * (r - l + 1);
      return;
    }
    long long mid = (l + r) >> 1;
    pushdown(rt, l, r);
    if (nl <= mid) modify(rt << 1, l, mid, nl, nr, k);
    if (nr > mid) modify(rt << 1 | 1, mid + 1, r, nl, nr, k);
    pushup(rt);
  }
  inline long long querymaxx(long long rt, long long l, long long r,
                             long long nl, long long nr) {
    if (nl <= l && r <= nr) {
      return maxx[rt];
    }
    long long ans = 0;
    long long mid = (l + r) >> 1;
    pushdown(rt, l, r);
    if (nl <= mid) ans = max(ans, querymaxx(rt << 1, l, mid, nl, nr));
    if (nr > mid) ans = max(ans, querymaxx(rt << 1 | 1, mid + 1, r, nl, nr));
    return ans;
  }
  inline long long queryminn(long long rt, long long l, long long r,
                             long long nl, long long nr) {
    if (nl <= l && r <= nr) {
      return minn[rt];
    }
    long long ans = INF;
    long long mid = (l + r) >> 1;
    pushdown(rt, l, r);
    if (nl <= mid) ans = min(ans, queryminn(rt << 1, l, mid, nl, nr));
    if (nr > mid) ans = min(ans, queryminn(rt << 1 | 1, mid + 1, r, nl, nr));
    return ans;
  }
  inline long long querysum(long long rt, long long l, long long r,
                            long long nl, long long nr) {
    if (nl <= l && r <= nr) {
      return sum[rt];
    }
    long long ans = 0;
    long long mid = (l + r) >> 1;
    pushdown(rt, l, r);
    if (nl <= mid) ans += querysum(rt << 1, l, mid, nl, nr);
    if (nr > mid) ans += querysum(rt << 1 | 1, mid + 1, r, nl, nr);
    return ans;
  }
} tree;
long long dp[400000];
int main() {
  int n, k;
  cin >> n >> k;
  long long ans = 0;
  vector<int> a(n + 1);
  for (int i = (1); i <= (n); i++) {
    cin >> a[i], a[i]++;
  }
  tree.buildtree(1, 1, 300001);
  for (int i = (1); i <= (n); i++) {
    int l = max(1, a[i] - k);
    int r = min(300001, a[i] + k);
    dp[a[i]] = max(dp[a[i]], tree.querymaxx(1, 1, 300001, l, r) + 1);
    tree.modify(1, 1, 300001, a[i], a[i], dp[a[i]]);
    ans = max(ans, dp[a[i]]);
  }
  cout << ans << endl;
  return 0;
}
