#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const long long INF = 1000000000;
class UnionFind {
 public:
  vector<int> par;
  UnionFind(int N) {
    par.resize(N);
    for (int i = 0; i < N; i++) par[i] = i;
  }
  int root(int A) {
    if (par[A] == A) return A;
    return par[A] = root(par[A]);
  }
  bool unite(int A, int B) {
    A = root(A);
    B = root(B);
    if (A == B) {
      return false;
    }
    par[B] = A;
    return true;
  }
  bool same(int x, int y) {
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }
};
template <class T>
class SegTree {
 public:
  int size;
  vector<T> seg;
  T e;
  function<T(T, T)> f;
  SegTree(T n, T _e, function<T(T, T)> _f) {
    f = _f;
    e = _e;
    size = 1;
    while (size < n) size *= 2;
    seg.resize(size * 2 - 1, e);
  }
  void updata(int n, int k) {
    n += size - 1;
    seg[n] = k;
    while (n > 0) {
      n = (n - 1) / 2;
      seg[n] = f(seg[n * 2 + 1], seg[n * 2 + 2]);
    }
  }
  T query(int a, int b, int l, int r, int k) {
    if (b <= l || r <= a) return e;
    if (a <= l && r <= b) return seg[k];
    T v1 = query(a, b, l, (l + r) / 2, k * 2 + 1);
    T v2 = query(a, b, (l + r) / 2, r, k * 2 + 2);
    return f(v1, v2);
  }
};
int main() {
  int n, k;
  cin >> n >> k;
  SegTree<int> tree(300001, 0, [](int a, int b) { return max(a, b); });
  vector<int> a(n);
  for (long long int i = (0); i < (n); i++) {
    cin >> a[i];
  }
  int ans = 0;
  for (long long int i = (0); i < (n); i++) {
    int l = max(0, a[i] - k - 1);
    int r = min(a[i] + k + 1, n);
    int sum = tree.query(l, r, 0, tree.size, 0) + 1;
    ans = max(ans, sum);
    tree.updata(i, sum);
  }
  cout << ans << endl;
  return 0;
}
