#include <bits/stdc++.h>
using namespace std;
long long mod = 1000000007;
long long dx[] = {-1, 1, 0, 0};
long long dy[] = {0, 0, 1, -1};
const long long inf = 1e12;
bool test = 0;
const long long N = 3e5 + 5;
long long mx[4 * N];
void update(long long n, long long st, long long end, long long pos,
            long long val) {
  if (st > pos or end < pos) return;
  if (st == end and st == pos) {
    mx[n] = max(mx[n], val);
    return;
  }
  long long mid = (st + end) / 2;
  update(2 * n, st, mid, pos, val);
  update(2 * n + 1, mid + 1, end, pos, val);
  mx[n] = max(mx[2 * n], mx[2 * n + 1]);
}
long long query(long long n, long long st, long long end, long long l,
                long long r) {
  if (l <= st && end <= r) return mx[n];
  long long m = (st + end) / 2;
  if (r <= m)
    return query(2 * n, st, m, l, r);
  else if (l > m)
    return query(2 * n + 1, m + 1, end, l, r);
  else {
    long long p1, p2;
    p1 = query(2 * n, st, m, l, r);
    p2 = query(2 * n + 1, m + 1, end, l, r);
    return max(p1, p2);
  }
}
long long st, last;
long long n, k, x;
void solve() {
  cin >> n >> k >> x;
  memset(mx, 0, sizeof(mx));
  st = 1, last = 300001;
  update(1, st, last, x, 1);
  for (long long i = 2; i <= n; ++i) {
    cin >> x;
    long long l = max(st, x - k);
    long long r = min(last, x + k);
    long long x1 = query(1, st, last, l, r);
    update(1, st, last, x, x1 + 1);
  }
  cout << query(1, st, last, st, last);
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t = 1;
  if (test) cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
