#include <bits/stdc++.h>
using namespace std;
int t[4 * 300005];
int n, k;
int sum(int v, int l, int r, int tl, int tr) {
  if (l > r) return 0;
  if (l == tl && r == tr) return t[v];
  int tm = (tl + tr) / 2;
  return max(sum(v * 2, l, min(r, tm), tl, tm),
             sum(v * 2 + 1, max(l, tm + 1), r, tm + 1, tr));
}
void update(int v, int cl, int cr, int pos) {
  if (cl == cr) {
    int l = pos - k;
    if (l < 0) l = 0;
    int r = pos + k;
    if (r > n) r = n;
    t[v] = 1 + sum(1, l, r, 0, n);
  } else {
    int cm = (cl + cr) / 2;
    if (pos <= cm) {
      update(v * 2, cl, cm, pos);
    } else {
      update(v * 2 + 1, cm + 1, cr, pos);
    }
    t[v] = max(t[v * 2], t[v * 2 + 1]);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n >> k;
  memset(t, 0, sizeof(t));
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    update(1, 0, n, a);
  }
  cout << t[1] << endl;
}
