#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;
int a[300010];
int b[300010];
struct STtree {
  struct tree {
    int a;
    int l, r;
    int tag;
    tree() : tag(0), l(0), r(0), a(0) {}
  } node[(int)1e6 << 2];
  STtree() {}
  STtree(int l, int r, int* a) { build(1, l, r, a); }
  inline void push_up(int x) {
    node[x].a = max(node[x << 1].a, node[x << 1 | 1].a);
  }
  inline int cmp(int a, int b) { return (a > b ? a : b); }
  void build(int x, int l, int r, int* 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;
    }
    int mid = (l + r) >> 1;
    build(x << 1, l, mid, a);
    build(x << 1 | 1, mid + 1, r, a);
    push_up(x);
  }
  void update(int left, int right, int x, int k) {
    if (left <= node[x].l && node[x].r <= right) {
      node[x].a = k;
      return;
    }
    int 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);
  }
  int query(int left, int right, int x) {
    int res = 0;
    if (left <= node[x].l && node[x].r <= right) return node[x].a;
    int 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;
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n, k;
  cin >> n >> k;
  for (int i = (1); i <= (n); i++) cin >> a[i], b[i] = a[i];
  sort(a + 1, a + 1 + n);
  int m = unique(a + 1, a + 1 + n) - a;
  st.build(1, 1, 1e6, 0);
  int ans = 0;
  for (int i = (1); i <= (n); i++) {
    int l = lower_bound(a + 1, a + 1 + m, b[i] - k) - a;
    int r = upper_bound(a + 1, a + 1 + m, b[i] + k) - a - 1;
    int t = st.query(l, r, 1);
    ans = max(ans, t + 1);
    int x = lower_bound(a + 1, a + 1 + m, b[i]) - a;
    st.update(x, x, 1, t + 1);
  }
  cout << ans;
}
