#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vd = vector<double>;
using vs = vector<string>;
using vpii = vector<pair<int, int>>;
using vpll = vector<pair<ll, ll>>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int N = 6e5 + 30;
int n;
int t[2 * N];
void build() {
  for (int i = n - 1; i > 0; --i) t[i] = max(t[i << 1], t[i << 1 | 1]);
}
void modify(int p, int value) {
  for (t[p + n] = max(value, t[p + n]), p += n; p > 1; p >>= 1)
    t[p >> 1] = max(t[p], t[p ^ 1]);
}
int query(int l, int r) {
  int res = 0;
  for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
    if (l & 1) res = max(res, t[l++]);
    if (r & 1) res = max(t[--r], res);
  }
  return res;
}
void solve() {
  int k;
  cin >> n >> k;
  vi a(n);
  for (ll i = 0; i < n; i++) cin >> a[i];
  ;
  for (int i = 0; i < n; i++) {
    int x = query(max(a[i] - k, 0), a[i] + k + 1);
    modify(a[i], x + 1);
  }
  cout << query(0, 3e5 + 7) << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll t = 1;
  while (t--) {
    solve();
  }
}
