#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
long long int gcd(long long int a, long long int b) {
  if (!b)
    return a;
  else
    return gcd(b, a % b);
}
class pointseg {
 private:
  int n;
  vector<long long int> t, a;
  void upd(int v, int tl, int tr, int pos, long long int val) {
    if (tl == tr) {
      t[v] = val;
      return;
    }
    int tm = (tl + tr) / 2;
    if (pos <= tm) {
      upd(2 * v, tl, tm, pos, val);
    } else {
      upd(2 * v + 1, tm + 1, tr, pos, val);
    }
    t[v] = merge(t[2 * v], t[2 * v + 1]);
  }
  long long int query(int v, int l, int r, int tl, int tr) {
    if (l > r) return 0;
    if (l == tl && r == tr) {
      return t[v];
    }
    int tm = (tl + tr) / 2;
    return merge(query(2 * v, l, min(r, tm), tl, tm),
                 query(2 * v + 1, max(l, tm + 1), r, tm + 1, tr));
  }
  void build(int v, int tl, int tr) {
    if (tl == tr) {
      t[v] = a[tl];
      return;
    }
    int tm = (tl + tr) / 2;
    build(2 * v, tl, tm);
    build(2 * v + 1, tm + 1, tr);
    t[v] = merge(t[2 * v], t[2 * v + 1]);
  }

 public:
  long long int merge(long long int a, long long int b) { return max(a, b); }
  void upd(int pos, long long int val) { upd(1, 1, n, pos, val); }
  long long int query(int l, int r) { return query(1, l, r, 1, n); }
  void build() { build(1, 1, n); }
  pointseg(int _n, vector<long long int> _a = {}) {
    n = _n;
    t.assign(4 * (n + 4), 0);
    a = _a;
  }
  pointseg() {}
  void reset(int _n, vector<long long int> _a = {}) {
    n = _n;
    t.clear();
    t.assign(4 * (_n + 4), 0);
    a.clear();
    a = _a;
  }
};
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long int n, k;
  cin >> n >> k;
  vector<long long int> a(n + 1);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    a[i]++;
  }
  long long int ans = 1;
  pointseg s(400000);
  for (int i = 0; i < n; i++) {
    long long int l = max(1LL, a[i] - k);
    long long int r = a[i] + k;
    long long int res = s.query(l, r);
    long long int now = s.query(a[i], a[i]);
    if (res + 1 > now) s.upd(a[i], res + 1);
    ans = max(ans, now);
    ans = max(ans, res + 1);
  }
  cout << ans;
}
