#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
ll mod2 = 998244353;
ll mod = 1e9 + 7;
vector<int> seg;
vector<int> dp;
void update(int v, int tl, int tr, int pos, int val) {
  if (tl == tr)
    seg[v] = val;
  else {
    int mid = (tl + tr) / 2;
    if (pos <= mid)
      update(2 * v, tl, mid, pos, val);
    else {
      update(2 * v + 1, mid + 1, tr, pos, val);
    }
    seg[v] = max(seg[2 * v], seg[2 * v + 1]);
  }
}
int get(int v, int tl, int tr, int l, int r) {
  if (tl > r || tr < l) return 0;
  if (tl >= l && tr <= r) return seg[v];
  int mid = (tl + tr) / 2;
  return max(get(2 * v, tl, mid, l, r), get(2 * v + 1, mid + 1, tr, l, r));
}
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n + 1);
  for (int i = 1; i <= n; i++) cin >> a[i];
  int p = *max_element(begin(a), end(a));
  seg.resize(p + 6, 0);
  int ans = 1;
  for (int i = 1; i <= n; i++) {
    int val = get(1, 1, p, max(0, a[i] - k), min(p, a[i] + k));
    update(1, 1, p, a[i], val + 1);
    ans = max(ans, val + 1);
  }
  cout << ans << endl;
}
