#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1e9 + 7;
const long long int MAXN = 1000200;
long long int i, j, mask, test;
vector<long long int> tree(MAXN), A(MAXN);
void update(long long int node, long long int start, long long int ends,
            long long int idx, long long int val) {
  if (start == ends) {
    A[idx] = val;
    tree[node] = val;
  } else {
    int mid = (start + ends) / 2;
    if (start <= idx and idx <= mid) {
      update(2 * node, start, mid, idx, val);
    } else {
      update(2 * node + 1, mid + 1, ends, idx, val);
    }
    tree[node] = max(tree[2 * node], tree[2 * node + 1]);
  }
}
long long int query(long long int node, long long int start, long long int ends,
                    long long int l, long long int r) {
  if (r < start || ends < l) {
    return 0;
  }
  if (l <= start && ends <= r) {
    return tree[node];
  }
  int mid = (start + ends) / 2;
  int p1 = query(2 * node, start, mid, l, r);
  int p2 = query(2 * node + 1, mid + 1, ends, l, r);
  return max(p1, p2);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long int n, k;
  cin >> n >> k;
  while (n--) {
    long long int x;
    cin >> x;
    long long int p =
        query(1, 0, MAXN - 1, max((long long int)0, x - k), x + k);
    update(1, 0, MAXN - 1, x, p + 1);
  }
  long long int maxx = 0;
  for (i = 0; i < MAXN; i++) {
    maxx = max(maxx, A[i]);
  }
  cout << maxx;
  return 0;
}
