#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
vector<int> tree, d;
int sz;
void init(int n) {
  sz = 1;
  while (sz < n) sz *= 2;
  tree.assign(2 * sz - 1, 0);
}
void st(int i, int v, int x, int lx, int rx) {
  if (rx - lx == 1) {
    tree[x] = v;
    return;
  }
  int m = (rx + lx) / 2;
  if (i < m) {
    st(i, v, 2 * x + 1, lx, m);
  } else {
    st(i, v, 2 * x + 2, m, rx);
  }
  tree[x] = max(tree[2 * x + 1], tree[2 * x + 2]);
}
void st(int i, int v) { st(i, v, 0, 0, sz); }
int mx(int l, int r, int x, int lx, int rx) {
  if (l >= rx || lx >= r) {
    return -2e9;
  }
  if (rx <= r && lx >= l) {
    return tree[x];
  }
  int m = (lx + rx) / 2;
  int m1 = mx(l, r, 2 * x + 1, lx, m);
  int m2 = mx(l, r, 2 * x + 2, m, rx);
  return max(m1, m2);
}
int mx(int l, int r) { return mx(l, r, 0, 0, sz); }
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  int m = -1;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    a[i] += k;
    m = max(m, a[i]);
  }
  init(m + k + 1);
  d.resize(m + 1);
  for (int i = 0; i < n; i++) {
    int cur = max(mx(a[i] - k, a[i]), mx(a[i] + 1, a[i] + k + 1)) + 1;
    if (cur > d[a[i]]) {
      st(a[i], cur);
      d[a[i]] = cur;
    }
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    ans = max(ans, d[a[i]]);
  }
  cout << ans;
  return 0;
}
