#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long power(long long first, unsigned long long second,
                unsigned long long m) {
  if (second == 0) return 1;
  long long p = power(first, second / 2, m) % m;
  p = (p * p) % m;
  return (second % 2 == 0) ? p : (first * p) % m;
}
long long modInverse(long long a, long long m) {
  { return power(a, m - 2, m); }
}
const long long maxn = 500003;
long long seg[maxn << 1];
long long arr[maxn];
void update(long long ind, long long l, long long r, long long pos,
            long long val) {
  if (l == r) {
    seg[ind] = val;
    return;
  }
  long long mid = l + r >> 1;
  if (mid >= pos) {
    update(ind * 2, l, mid, pos, val);
  } else
    update(ind * 2 + 1, mid + 1, r, pos, val);
  seg[ind] = max(seg[ind * 2], seg[ind * 2 + 1]);
}
long long cnt = 0;
long long query(long long l, long long r, long long ind, long long L,
                long long R) {
  if (L > R) return 0;
  if (l >= L && r <= R) {
    return seg[ind];
  }
  long long mid = l + r >> 1;
  long long ret = 0;
  ret = max(query(l, mid, ind * 2, L, min(R, mid)),
            query(mid + 1, r, ind * 2 + 1, max(L, mid + 1), R));
  return ret;
}
void solve() {
  long long n;
  cin >> n;
  long long first;
  long long k;
  cin >> k;
  long long ans = 0;
  for (long long i = 1; i <= n; i++) {
    cin >> first;
    long long p =
        query(1, 300000, 1, max(0LL, first - k), min(first + k, 600000LL));
    update(1, 1, 300000, first, p + 1);
  }
  cout << seg[1] << "\n";
}
signed main() {
  ios_base ::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  solve();
  return 0;
}
