#include <bits/stdc++.h>
using namespace std;
constexpr int INF = INT_MAX >> 1;
constexpr long long LINF = 5000000000000000LL;
constexpr int MOD = 1000000007;
vector<int> mx(1 << 20, 0);
void update(int a, int q) {
  a += 1 << 19;
  mx[a] = max(mx[a], q);
  while ((a /= 2) > 0) mx[a] = max(mx[a * 2], mx[a * 2 + 1]);
}
int query(int l, int r, int sl = 0, int sr = 1 << 19, int a = 1) {
  if (r <= sl || sr <= l) return 0;
  if (l <= sl && sr <= r) return mx[a];
  int sm = (sl + sr) / 2;
  int lmx = query(l, r, sl, sm, a * 2);
  int rmx = query(l, r, sm, sr, a * 2 + 1);
  return max(lmx, rmx);
}
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (int i = 0; i < (n); i++) cin >> a[i];
  for (int i = 0; i < (n); i++) {
    update(a[i], query(max(a[i] - k, 1), a[i] + k + 1) + 1);
  }
  cout << query(1, 300001) << endl;
}
