#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 10;
const int MOD = 1e9 + 7;
const int64_t INF = 5e18;
const double PI = 2 * acos(0.0);
int tree[4 * N], a[N], cnt[N];
void update(int p, int b, int e, int l, int r, int v) {
  if (b > r || e < l) {
    return;
  } else if (b >= l && e <= r) {
    tree[p] = v;
  } else {
    int m = b + e >> 1;
    update(p * 2, b, m, l, r, v);
    update(p * 2 + 1, m + 1, e, l, r, v);
    tree[p] = max(tree[p * 2], tree[p * 2 + 1]);
  }
}
int query(int p, int b, int e, int l, int r) {
  if (b > r || e < l) {
    return 0;
  } else if (b >= l && e <= r) {
    return tree[p];
  } else {
    int m = b + e >> 1;
    return max(query(p * 2, b, m, l, r), query(p * 2 + 1, m + 1, e, l, r));
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    cnt[a[i]]++;
  }
  int mxN = 3e5;
  for (int i = 0; i < n; i++) {
    int bck = max(a[i] - k, 1);
    int fnt = min(a[i] + k, mxN);
    int gotMax = max(query(1, 1, mxN, bck, a[i]), query(1, 1, mxN, a[i], fnt));
    update(1, 1, mxN, a[i], a[i], gotMax + 1);
  }
  cout << query(1, 1, mxN, 1, mxN) << '\n';
  return 0;
}
