#include <bits/stdc++.h>
using namespace std;
int p[300010], ans[300010], t[1400100];
void modify(int ind, int L, int R, int tar, int x) {
  if (L == R) {
    t[ind] = max(t[ind], x);
    return;
  }
  int M = (L + R) >> 1;
  if (tar <= M)
    modify(ind * 2, L, M, tar, x);
  else
    modify(ind * 2 + 1, M + 1, R, tar, x);
  t[ind] = max(t[ind * 2], t[ind * 2 + 1]);
}
int query(int ind, int L, int R, int ql, int qr) {
  if (L == ql && R == qr) return t[ind];
  int M = (L + R) >> 1;
  if (qr <= M)
    return query(ind * 2, L, M, ql, qr);
  else if (ql > M)
    return query(ind * 2 + 1, M + 1, R, ql, qr);
  else
    return max(query(ind * 2, L, M, ql, M),
               query(ind * 2 + 1, M + 1, R, M + 1, qr));
}
int solve(int x, int k) {
  int l = max(1, x - k), r = min(300000, x + k);
  return query(1, 1, 300000, l, r);
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < n; i++) cin >> p[i];
  int ans = 0;
  for (int i = 0; i < n; i++) {
    ans = max(ans, solve(p[i], k) + 1);
    modify(1, 1, 300000, p[i], ans);
  }
  cout << ans << endl;
}
