#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 1000;
int n, k;
vector<int> t;
void build() {
  for (int i = n - 1; i > 0; i--) t[i] = max(t[2 * i], t[2 * i + 1]);
}
void update(int pos, int val) {
  pos += n;
  t[pos] = val;
  for (; pos > 1; pos /= 2) t[pos / 2] = max(t[pos], t[pos ^ 1]);
}
int query(int l, int r) {
  r++;
  l = max(0, l);
  r = min(N, r);
  int res = 0;
  for (l += n, r += n; l < r; l /= 2, r /= 2) {
    if (l & 1) res = max(res, t[l++]);
    if (r & 1) res = max(res, t[--r]);
  }
  return res;
}
void solve() {
  cin >> n >> k;
  int ans = 0;
  t.resize(N, 0);
  for (int i = 0; i < n; i++) {
    int cur;
    cin >> cur;
    int mx = query(cur - k, cur + k);
    update(cur, mx + 1);
  }
  for (int i = 0; i < N; i++) ans = max(ans, t[i]);
  cout << ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  solve();
}
