#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 2;
int a[maxn];
int tree[maxn << 2];
struct seg_tree {
  int combine(int x, int y) { return max(x, y); }
  void build(int l, int r, int node) {
    if (l == r) {
      tree[node] = a[l];
      return;
    }
    int mid = l + r >> 1, lc = node + node, rc = 1 + lc;
    build(l, mid, lc);
    build(mid + 1, r, rc);
    tree[node] = combine(tree[lc], tree[rc]);
  }
  int query(int l, int r, int ql, int qr, int node) {
    if (qr < l || r < ql) return 0;
    if (ql <= l and r <= qr) {
      return tree[node];
    }
    int mid = l + r >> 1, lc = node + node, rc = 1 + lc;
    return combine(query(l, mid, ql, qr, lc), query(mid + 1, r, ql, qr, rc));
  }
  void update(int l, int r, int pos, int val, int node) {
    if (pos < l || r < pos) return;
    if (l == r and l == pos) {
      tree[node] = val;
      return;
    }
    int mid = l + r >> 1, lc = node + node, rc = 1 + lc;
    update(l, mid, pos, val, lc);
    update(mid + 1, r, pos, val, rc);
    tree[node] = combine(tree[lc], tree[rc]);
  }
};
void solve() {
  int n, k;
  cin >> n >> k;
  const int mx = 3e5;
  seg_tree ins;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    int l = max(0, a[i] - k);
    int r = min(mx, a[i] + k);
    int ans = 1 + ins.query(1, mx, l, r, 1);
    ins.update(1, mx, a[i], ans, 1);
  }
  for (int i = 1; i <= 10; ++i) {
  }
  cout << ins.query(1, mx, 1, mx, 1) << '\n';
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  for (int i = 1; i <= t; ++i) {
    solve();
  }
  return 0;
}
