#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 50;
int maxx[maxn << 2], a[maxn], f[maxn];
void change(int rt, int l, int r, int pos, int v) {
  if (l == r && l == pos) {
    maxx[l] = v;
    return;
  }
  int mid = (l + r) >> 1;
  if (pos > mid)
    change(rt << 1 | 1, mid + 1, r, pos, v);
  else
    change(rt << 1, l, mid, pos, v);
  maxx[rt] = max(maxx[rt << 1], maxx[rt << 1 | 1]);
}
int query(int rt, int l, int r, int x, int y) {
  if (x >= l && r <= y) {
    return maxx[rt];
  }
  int ans = 0;
  int mid = (l + r) >> 1;
  if (mid >= x) ans = max(ans, query(rt << 1, l, mid, x, y));
  if (mid < y) ans = max(ans, query(rt << 1 | 1, mid + 1, r, x, y));
  return ans;
}
int n, k;
int main() {
  cin >> n >> k;
  for (int i = 1; i <= n; ++i) cin >> a[i];
  f[1] = 1;
  change(1, 0, 3e5, a[1], 1);
  for (int i = 2; i <= n; ++i) {
    int now = query(1, 0, 3e5, max(a[i] - k, 0), min(300000, a[i] + k));
    f[i] = max(1, now + 1);
    now = query(1, 0, 3e5, a[i], a[i]);
    if (now < f[i]) change(1, 0, 3e5, a[i], f[i]);
  }
  int Max = 0;
  for (int i = 1; i <= n; ++i) Max = max(f[i], Max);
  cout << Max << endl;
  return 0;
}
