#include <bits/stdc++.h>
using namespace std;
int n, k, a[300010], dp[300010];
struct node {
  int sum;
} tree[300010 << 2];
int read() {
  int s = 0, f = 0;
  char ch = getchar();
  while (!isdigit(ch)) f |= (ch == '-'), ch = getchar();
  while (isdigit(ch)) s = s * 10 + (ch ^ 48), ch = getchar();
  return f ? -s : s;
}
void push_up(int rt) {
  tree[rt].sum = max(tree[rt << 1].sum, tree[rt << 1 | 1].sum);
}
void build(int rt, int l, int r) {
  tree[rt].sum = 0;
  if (l == r) return;
  int mid = (l + r) >> 1;
  build(rt << 1, l, mid), build(rt << 1 | 1, mid + 1, r);
  push_up(rt);
}
void change(int rt, int c, int l, int r, int pos) {
  if (l == r) {
    tree[rt].sum = c;
    return;
  }
  int mid = (l + r) >> 1;
  if (pos <= mid)
    change(rt << 1, c, l, mid, pos);
  else
    change(rt << 1 | 1, c, mid + 1, r, pos);
  push_up(rt);
}
int query(int rt, int l, int r, int L, int R) {
  if (L <= l && r <= R) return tree[rt].sum;
  int mid = (l + r) >> 1, ans = 1;
  if (L <= mid) ans = max(ans, query(rt << 1, l, mid, L, R));
  if (R > mid) ans = max(ans, query(rt << 1 | 1, mid + 1, r, L, R));
  return ans;
}
int main() {
  n = read(), k = read();
  int m = 0;
  for (int i = 1; i <= n; i++) a[i] = read(), m = max(a[i], m);
  build(1, 1, m);
  for (int i = 1; i <= n; i++) {
    dp[i] = query(1, 1, m, max(a[i] - k, 1), min(a[i] + k, n));
    change(1, dp[i] + 1, 1, m, a[i]);
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) ans = max(ans, dp[i]);
  cout << ans << "\n";
}
