#include <bits/stdc++.h>
using namespace std;
const int N = 366666;
int n, k, arr[N];
int dp[N];
struct Node {
  int l, r;
  int maxn;
} tr[N << 2];
void pushup(int u) {
  tr[u].maxn = max(tr[u << 1].maxn, tr[u << 1 | 1].maxn);
  return;
}
void build(int u, int l, int r) {
  tr[u].l = l, tr[u].r = r;
  if (l == r) {
    tr[u].maxn = 0;
    return;
  }
  int mid = (l + r) / 2;
  build(u << 1, l, mid), build(u << 1 | 1, mid + 1, r);
  pushup(u);
}
int querymax(int u, int l, int r) {
  if (l <= tr[u].l && tr[u].r <= r) {
    return tr[u].maxn;
  }
  int mx = 0;
  int mid = (tr[u].l + tr[u].r) >> 1;
  if (l <= mid) mx = max(mx, querymax(u << 1, l, r));
  if (r > mid) mx = max(mx, querymax(u << 1 | 1, l, r));
  return mx;
}
void modify(int u, int x, int y) {
  if (tr[u].l == x && tr[u].r == x) {
    tr[u].maxn = max(tr[u].maxn, y);
    return;
  }
  int mid = (tr[u].l + tr[u].r) >> 1;
  if (x <= mid)
    modify(u << 1, x, y);
  else
    modify(u << 1 | 1, x, y);
  pushup(u);
}
signed main() {
  cin >> n >> k;
  for (int i = 1; i <= n; i++) cin >> arr[i];
  build(1, 0, 300001);
  for (int i = 1; i <= n; i++) {
    int l = max(0, arr[i] - k);
    int r = min(300001, arr[i] + k);
    dp[i] = querymax(1, l, r) + 1;
    modify(1, arr[i], dp[i]);
  }
  cout << dp[n];
  return 0;
}
