#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using ll = long long;
using ull = unsigned long long;
constexpr int INF = 1073741823;
constexpr int MINF = -1073741823;
constexpr ll LINF = ll(4661686018427387903);
constexpr ll MOD = 1e9 + 7;
constexpr ll mod = 998244353;
constexpr long double eps = 1e-6;
const long double PI = acosl(-1.0L);
using namespace std;
void scans(string& str) {
  char c;
  str = "";
  scanf("%c", &c);
  if (c == '\n') scanf("%c", &c);
  while (c != '\n' && c != -1 && c != ' ') {
    str += c;
    scanf("%c", &c);
  }
}
void scanc(char& str) {
  char c;
  scanf("%c", &c);
  if (c == -1) return;
  while (c == '\n') {
    scanf("%c", &c);
  }
  str = c;
}
double acot(double x) { return PI / 2 - atan(x); }
ll LSB(ll n) { return (n & (-n)); }
template <typename T>
inline T chmin(T& a, const T& b) {
  if (a > b) a = b;
  return a;
}
template <typename T>
inline T chmax(T& a, const T& b) {
  if (a < b) a = b;
  return a;
}
template <typename T, typename F>
struct segtree {
  vector<T> seg;
  int siz;
  const T e;
  const F f;
  segtree(int n, const T a, const F f) : e(a), f(f) {
    siz = 1;
    while (siz < n) siz <<= 1;
    seg.assign(2 * siz - 1, e);
    --siz;
  }
  void set(int k, const T& t) { seg[k + siz] = t; }
  void build() {
    for (int i = siz - 1; i >= 0; --i)
      seg[i] = f(seg[i * 2 + 1], seg[i * 2 + 2]);
  }
  T operator[](const int i) { return seg[i + siz]; }
  void update(int k, T a) {
    k += siz;
    seg[k] = a;
    while (k > 0) {
      k = ((k - 1) >> 1);
      seg[k] = f(seg[k * 2 + 1], seg[k * 2 + 2]);
    }
  }
  T query(int a, int b) {
    T l = e, r = e;
    for (a += siz, b += siz; a < b; a >>= 1, b >>= 1) {
      if (!(a & 1)) l = f(l, seg[a++]);
      if (!(b & 1)) r = f(seg[--b], r);
    }
    return f(l, r);
  }
  template <typename C, typename FT>
  int find(const int start, const int end, int l, int r, int k, const C check,
           T& checknum, const bool b, const FT revf) {
    if (start <= l && r <= end && !check(seg[k], checknum)) {
      checknum = revf(checknum, seg[k]);
      return -1;
    }
    if ((r <= start || l >= end)) {
      return -1;
    }
    if (k >= siz) {
      return k - siz;
    }
    int res;
    if (b) {
      res = find<C, FT>(start, end, l, ((l + r) >> 1), (k << 1) + 1, check,
                        checknum, b, revf);
      if (res != -1) return (res);
      return find<C, FT>(start, end, ((l + r) >> 1), r, (k << 1) + 2, check,
                         checknum, b, revf);
    } else {
      res = find<C, FT>(start, end, ((l + r) >> 1), r, (k << 1) + 2, check,
                        checknum, b, revf);
      if (res != -1) return (res);
      return find<C, FT>(start, end, l, ((l + r) >> 1), (k << 1) + 1, check,
                         checknum, b, revf);
    }
  }
  template <typename C, typename FT>
  int find_left(int start, int end, const C check, T checknum, FT revf) {
    return find<C, FT>(start, end, 0, siz + 1, 0, check, checknum, true, revf);
  }
  template <typename C, typename FT>
  int find_right(int start, int end, const C check, T checknum, FT revf) {
    return find<C, FT>(start, end, 0, siz + 1, 0, check, checknum, false, revf);
  }
};
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  auto f = [](int a, int b) { return max(a, b); };
  segtree<int, decltype(f)> seg(300001, 0, f);
  seg.build();
  int ans = 1, a;
  for (int i = 0; i < (n); ++i) {
    scanf("%d", &a);
    seg.update(
        a, chmax(ans, seg.query(max(0, a - k), min(a + k + 1, 300001))) + 1);
  }
  printf("%d\n", ans);
  return 0;
}
