#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1001001001;
const int MOD = 1000000007;
template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T &a, T b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T>
struct SegTree {
  using F = function<T(T, T)>;
  int size;
  vector<T> data;
  const F f;
  const T t0;
  SegTree(int n, const F f, const T &t0) : f(f), t0(t0) {
    size = 1;
    while (size < n) size *= 2;
    data.assign(size * 2 - 1, t0);
  }
  SegTree(vector<T> &vec, const F f, const T &t0) : f(f), t0(t0) {
    size = 1;
    while (size < int(vec.size())) size *= 2;
    data.assign(size * 2 - 1, t0);
    for (int i = 0; i < (min(int(vec.size()), size)); i++)
      data[i + size - 1] = vec[i];
    for (int i = size - 2; i >= 0; i--)
      data[i] = f(data[i * 2 + 1], data[i * 2 + 2]);
  }
  void update(int x, const T &val) {
    x += size - 1;
    data[x] = val;
    while (x) {
      x = (x - 1) / 2;
      data[x] = f(data[x * 2 + 1], data[x * 2 + 2]);
    }
  }
  T query(int a, int b, int k = 0, int l = 0, int r = -1) {
    if (r < 0) r = size;
    if (r <= a || l >= b) return t0;
    if (a <= l && b >= r) return data[k];
    T vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
    T vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
    return f(vl, vr);
  }
};
int main() {
  int n, k;
  cin >> n >> k;
  const int MAX_I = 300010;
  SegTree<int> seg(
      MAX_I, [](int a, int b) { return max(a, b); }, 0);
  for (int i = 0; i < (n); i++) {
    int x;
    cin >> x;
    int l = max(0, x - k), r = min(MAX_I - 1, x + k);
    int maxNum = seg.query(l, r + 1);
    ;
    seg.update(x, maxNum + 1);
    ;
  }
  cout << seg.query(0, n + 1) << endl;
}
