#include <bits/stdc++.h>
using namespace std;
const int NMAX = 3e5 + 10;
const int MOD = 1e9 + 7;
int Max[NMAX << 3];
int maxx[NMAX], a[NMAX];
void push_up(int rt) { Max[rt] = max(Max[rt << 1], Max[rt << 1 | 1]); }
void update(int pos, int c, int l, int r, int rt) {
  if (l == r) {
    Max[rt] = c;
    return;
  }
  int mid = (l + r) >> 1;
  if (pos <= mid)
    update(pos, c, l, mid, rt << 1);
  else
    update(pos, c, mid + 1, r, rt << 1 | 1);
  push_up(rt);
}
int queryMax(int L, int R, int l, int r, int rt) {
  if (L <= l && r <= R) return Max[rt];
  int mid = (l + r) >> 1;
  int ans = 0;
  if (L <= mid) ans = max(ans, queryMax(L, R, l, mid, rt << 1));
  if (R > mid) ans = max(ans, queryMax(L, R, mid + 1, r, rt << 1 | 1));
  return ans;
}
int main(int argc, char const *argv[]) {
  int n, k;
  scanf("%d%d", &n, &k);
  for (register int i = 1; i <= n; i++) scanf("%d", a + i), a[i]++;
  int ans = 0, ant;
  for (register int i = 1; i <= n; i++) {
    ant = 1 + queryMax(max(1, a[i] - k), min(a[i] + k, n + k + 10), 1,
                       n + k + 10, 1);
    if (maxx[a[i]] < ant) {
      maxx[a[i]] = ant;
      update(a[i], ant, 1, n + k + 10, 1);
    }
    ans = max(ans, ant);
  }
  printf("%d\n", ans);
  return 0;
}
