#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
const int N = 3e6 + 5;
pair<long long, long long> p;
stack<int> st1;
string s, s1;
char o;
bool mark[N], h;
vector<long long> vt[N], vm, vs;
long long a[N], b[N], c, d, dp[N], dis, tree[N];
bool vowel(char che) {
  if (che == 'A' || che == 'E' || che == 'I' || che == 'O' || che == 'U' ||
      che == 'Y') {
    return true;
  } else {
    return false;
  }
}
long long pw(long long a, long long b) {
  long long ans = 1;
  while (b) {
    if (b % 2 == 1) {
      ans *= a;
      ans %= mod;
    }
    b /= 2;
    a *= a;
  }
  return ans;
}
void build(long long st, long long ed, long long node) {
  if (st == ed)
    tree[node] = 0;
  else {
    long long mid = (st + ed) / 2;
    build(st, mid, 2 * node);
    build(mid + 1, ed, (2 * node) + 1);
    tree[node] = max(tree[node * 2], tree[(2 * node) + 1]);
  }
}
long long update(long long node, long long st, long long ed, long long id,
                 long long val) {
  if (st == ed)
    tree[node] = val;
  else {
    long long mid = (st + ed) / 2;
    if (id <= mid)
      update(2 * node, st, mid, id, val);
    else
      update((2 * node) + 1, mid + 1, ed, id, val);
    tree[node] = max(tree[2 * node], tree[(2 * node) + 1]);
  }
}
long long query(long long node, long long st, long long ed, long long l,
                long long r) {
  if (r < st || l > ed) return 0;
  if (l <= st && ed <= r) return tree[node];
  long long mid = (st + ed) / 2;
  long long q1 = query(2 * node, st, mid, l, r);
  long long q2 = query((2 * node) + 1, mid + 1, ed, l, r);
  return max(q1, q2);
}
int main() {
  long long t = 0, n, m = 0, k = 0, f = 0, sum = 0, ans = 0;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n; i++) {
    long long l = max(long long(0), a[i] - k);
    long long r = min(long long(3e5), a[i] + k);
    ans = query(1, 0, 3e5, l, r) + 1;
    update(1, 0, 3e5, a[i], ans);
  }
  cout << tree[1] << endl;
}
