#include <bits/stdc++.h>
using namespace std;
const int N = 6e5 + 5;
int n, m, x, k, a[N], tree[N << 2], ans = 0;
void pushup(int i) { tree[i] = max(tree[i << 1], tree[i << 1 | 1]); }
void update(int i, int l, int r, int x, int k) {
  if (l == r) {
    tree[i] = max(tree[i], k);
    return;
  }
  int mid = l + (r - l) / 2;
  if (x <= mid)
    update(i << 1, l, mid, x, k);
  else
    update(i << 1 | 1, mid + 1, r, x, k);
  pushup(i);
}
int query(int i, int l, int r, int m, int n) {
  if (m <= l && r <= n) return tree[i];
  int ans = 0, mid = l + (r - l) / 2;
  if (m <= mid) ans = max(ans, query(i << 1, l, mid, m, n));
  if (n > mid) ans = max(ans, query(i << 1 | 1, mid + 1, r, m, n));
  return ans;
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]), a[i]++;
  for (int i = 1; i <= n; i++) {
    x = query(1, 1, 300001, max(a[i] - k, 1), min(a[i] + k, 300001)) + 1;
    ans = max(ans, x);
    update(1, 1, 300001, a[i], x);
  }
  printf("%d", ans);
  return 0;
}
