#include <bits/stdc++.h>
using namespace std;
const int N = 6e5 + 20, L = log(N) + 5;
int n, k, a[N], ans;
struct node {
  int val;
} tree[N << 2];
void update(int node, int start, int end, int idx, int val) {
  struct node &parent = tree[node];
  if (start == end) {
    parent.val = val;
  } else {
    int mid = (start + end) >> 1;
    if (start <= idx and idx <= mid)
      update(node << 1, start, mid, idx, val);
    else
      update((node << 1) + 1, mid + 1, end, idx, val);
    struct node left_child = tree[node << 1];
    struct node right_child = tree[(node << 1) + 1];
    parent.val = max(left_child.val, right_child.val);
  }
}
int query(int node, int start, int end, int l, int r) {
  if (r < start or end < l) return 0;
  struct node &parent = tree[node];
  if (l <= start and end <= r) return parent.val;
  int mid = (start + end) >> 1;
  int p1 = query(node << 1, start, mid, l, r);
  int p2 = query((node << 1) + 1, mid + 1, end, l, r);
  return max(p1, p2);
}
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++) {
    int l = 0, r = 0;
    if (a[i] - k >= 0) l = query(1, 1, n, max(1, a[i] - k), a[i]);
    r = query(1, 1, n, a[i], a[i] + k);
    int mx = max(l, r) + 1;
    ans = max(ans, mx);
    update(1, 1, n, a[i], mx);
  }
  printf("%d", ans);
}
