#include <bits/stdc++.h>
using namespace std;
template <class C>
void min_self(C &a, C b) {
  a = min(a, b);
}
template <class C>
void max_self(C &a, C b) {
  a = max(a, b);
}
const long long MOD = 1000000007;
long long mod(long long n, long long m = MOD) {
  n %= m, n += m, n %= m;
  return n;
}
const int MAXN = 1e5 + 5;
const int LOGN = 21;
const long long INF = 1e14;
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
template <class T1, class T2>
void add(T1 &x, T2 y, long long m = MOD) {
  x += y;
  if (x >= m) x -= m;
}
template <class T1, class T2>
void sub(T1 &x, T2 y, long long m = MOD) {
  x -= y;
  if (x < 0) x += m;
}
vector<int> seg;
int N;
void update(int pos, long long val) {
  pos += N;
  seg[pos] = val;
  for (; pos > 1; pos >>= 1) seg[pos / 2] = max(seg[pos], seg[pos ^ 1]);
}
int query(int l, int r) {
  l += N;
  r += N + 1;
  int ans = 0;
  for (; l < r; l >>= 1, r >>= 1) {
    if (l & 1) ans = max(ans, seg[l++]);
    if (r & 1) ans = max(ans, seg[--r]);
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n, k;
  cin >> n >> k;
  N = 600100;
  seg.clear();
  seg.resize(2 * N);
  for (int i = 0; i < n; i++) {
    long long x;
    cin >> x;
    int get = query(max(0ll, x - k), x + k);
    update(x, max(seg[x], get + 1));
  }
  cout << query(0, N - 1), cout << "\n";
  cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
  return 0;
}
