#include <bits/stdc++.h>
#pragma warning(disable : 4996)
using namespace std;
const double pi = acos(-1);
const double eps = 1e-5;
const int INF = 0x3f3f3f3f;
const long long int INFLL = 0x3f3f3f3f3f3f3f3f;
long long a[300010];
long long b[300010];
struct STtree {
  struct tree {
    long long a;
    long long l, r;
    long long tag;
    tree() : tag(0), l(0), r(0), a(0) {}
  } node[(long long)1e6 << 2];
  STtree() {}
  STtree(long long l, long long r, long long* a) { build(1, l, r, a); }
  inline void push_up(long long x) {
    node[x].a = max(node[x << 1].a, node[x << 1 | 1].a);
  }
  inline long long cmp(long long a, long long b) { return (a > b ? a : b); }
  void build(long long x, long long l, long long r, long long* a) {
    node[x].l = l;
    node[x].r = r;
    node[x].tag = 0;
    if (l == r) {
      if (!a)
        node[x].a = 0;
      else
        node[x].a = a[l];
      return;
    }
    long long mid = (l + r) >> 1;
    build(x << 1, l, mid, a);
    build(x << 1 | 1, mid + 1, r, a);
    push_up(x);
  }
  void update(long long left, long long right, long long x, long long k) {
    if (left <= node[x].l && node[x].r <= right) {
      node[x].a = k;
      return;
    }
    long long mid = (node[x].l + node[x].r) >> 1;
    if (left <= mid) update(left, right, x << 1, k);
    if (right > mid) update(left, right, x << 1 | 1, k);
    push_up(x);
  }
  long long query(long long left, long long right, long long x) {
    long long res = 0;
    if (left <= node[x].l && node[x].r <= right) return node[x].a;
    long long mid = (node[x].l + node[x].r) >> 1;
    if (left <= mid) res = max(res, query(left, right, x << 1));
    if (right > mid) res = max(res, query(left, right, x << 1 | 1));
    return res;
  }
} st;
signed main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  long long n, k;
  cin >> n >> k;
  for (long long i = (1); i <= (n); i++) cin >> a[i], b[i] = a[i];
  sort(a + 1, a + 1 + n);
  long long m = unique(a + 1, a + 1 + n) - a;
  st.build(1, 1, 1e6, 0);
  long long ans = 0;
  for (long long i = (1); i <= (n); i++) {
    long long l = lower_bound(a + 1, a + 1 + m, b[i] - k) - a;
    long long r = upper_bound(a + 1, a + 1 + m, b[i] + k) - a - 1;
    long long t = st.query(l, r, 1);
    ans = max(ans, t + 1);
    long long x = lower_bound(a + 1, a + 1 + m, b[i]) - a;
    st.update(x, x, 1, t + 1);
  }
  cout << ans;
}
