#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const long long INF = 1001001001;
const long long MOD = 998244353;
const double EPS = 1e-10;
template <typename T>
struct SegTree {
  int n;
  T e;
  vector<T> d;
  SegTree(int n, T e) : n(n + 1), e(e), d(2 * n + 2, e) {}
  T op(T x, T y) { return max(x, y); }
  void update(int i, T x) {
    i += n;
    d[i] = x;
    while (i > 1) {
      i >>= 1;
      d[i] = op(d[i << 1], d[i << 1 | 1]);
    }
  }
  T find(int l, int r) {
    T res = e;
    l += n;
    r += n;
    while (l < r) {
      if (l & 1) res = op(res, d[l++]);
      if (r & 1) res = op(d[--r], res);
      l >>= 1, r >>= 1;
    }
    return res;
  }
};
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, k;
  cin >> n >> k;
  ll a[n];
  for (int i = 0; i < n; i++) cin >> a[i], a[i] += 300000;
  SegTree<int> sg(606060, 0);
  for (int i = 0; i < n; i++) {
    int t = sg.find(a[i] - k, a[i] + k + 1);
    sg.update(a[i], t + 1);
  }
  cout << sg.find(0, 606060) << endl;
}
