#include <bits/stdc++.h>
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast", "unroll-loops", "omit-frame-pointer", "inline")
using namespace std;
const int N = 3e5 + 10;
int a[N], n, m, k, len, dp[N], ans, tr[N << 2];
int query(int x, int y, int l, int r, int rt) {
  int mid = (l + r) / 2;
  int maxn = 0;
  if (x <= l && r <= y) return tr[rt];
  if (x <= mid) maxn = max(maxn, query(x, y, l, mid, rt << 1));
  if (y > mid) maxn = max(maxn, query(x, y, mid + 1, r, rt << 1 | 1));
  return maxn;
}
void pushup(int rt) { tr[rt] = max(tr[rt << 1], tr[rt << 1 | 1]); }
void change(int nt, int l, int r, int rt, int k) {
  if (l == r) {
    tr[rt] = max(tr[rt], k);
    return;
  }
  int mid = (l + r) >> 1;
  if (nt <= mid)
    change(nt, l, mid, rt << 1, k);
  else
    change(nt, mid + 1, r, rt << 1 | 1, k);
  pushup(rt);
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    len = max(len, a[i] + k);
  }
  for (int i = 1; i <= n; i++) a[i]++;
  for (int i = 1; i <= n; i++) {
    int l = max(a[i] - k, 1), r = a[i] + k;
    dp[i] = query(l, r, 1, len, 1) + 1;
    change(a[i], 1, len, 1, dp[i]);
    ans = max(ans, dp[i]);
  }
  printf("%d\n", ans);
  return 0;
}
