#include <bits/stdc++.h>
using namespace std;
const int N = 6e5 + 7;
int n, a[N], k, tree[4 * N];
void update(int pos, int v, int l, int r, int node) {
  if (l == r) {
    tree[node] = v;
  }
  if (pos <= (l + r) / 2)
    update(pos, v, l, (l + r) / 2, 2 * node);
  else
    update(pos, v, (l + r) / 2 + 1, r, 2 * node + 1);
  tree[node] = max(tree[2 * node], tree[2 * node + 1]);
}
int query(int ql, int qr, int l, int r, int node) {
  if (ql <= l && qr >= r) {
    return tree[node];
  }
  int ans = 0;
  if (ql <= (l + r) / 2)
    ans = max(ans, query(ql, qr, l, (l + r) / 2, 2 * node));
  if (qr > (l + r) / 2)
    ans = max(ans, query(ql, qr, (l + r) / 2 + 1, r, 2 * node + 1));
  return ans;
}
int main() {
  scanf("%d %d", &n, &k);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    int res = query(max(a[i] - k, 0), a[i] + k, 0, N, 1) + 1;
    ans = max(ans, res);
    update(a[i], res, 0, N, 1);
  }
  cout << ans << endl;
}
