#include <bits/stdc++.h>
using namespace std;
int a[300005], mx[100005], b[300005];
void change(long long x) {
  while (x <= 300001) {
    mx[x] = b[x];
    for (long long i = 1; i < (x & (-x)); i <<= (long long)1) {
      mx[x] = max(mx[x], mx[x - i]);
    }
    x += x & (-x);
  }
}
int getmx(long long l, long long r) {
  int res = b[r];
  while (l <= r) {
    res = max(res, b[r]);
    for (--r; r - l >= (r & (-r)); r -= (r & (-r))) {
      res = max(res, mx[r]);
    }
  }
  return res;
}
int main() {
  int n, k;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    a[i]++;
  }
  for (int i = 1; i <= n; i++) {
    int l = max(1, a[i] - k), r = min(300001, a[i] + k);
    int v = getmx(l, r);
    b[a[i]] = v + 1;
    change(a[i]);
  }
  cout << getmx(1, 300001) << endl;
}
