#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define repr(i, n) for (int i = (int)n - 1; i >= 0; --i)
#define ALL(a) (a).begin(), (a).end()
using ll = long long;
using Graph = vector<vector<int>>;
// using P = pair<ll, ll>;
const int dx[] = {0, 1, -1, 0};
const int dy[] = {1, 0, 0, -1};
const ll mod = 1e9 + 7;
const ll INF = 1e9;
const ll LINF = 1LL << 60;

#define MAX 300000

int op(int a, int b) { return max(a, b); }
int e() { return 0; }

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  //////////////////////////////////////
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  segtree<int, op, e> dp(MAX);
  rep(i, n) {
    int x = a[i];
    int l = x - k, r = x + k + 1;
    l = max(l, 0);
    r = min(r, MAX);
    int now = dp.prod(l, r) + 1;
    // dp.set(x, max(dp.get(x), now));
    dp.set(x, now);
  }
  int ans = dp.prod(0, MAX);
  cout << ans << endl;
  return 0;
}