#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
struct LazySegmentTree {
 private:
  long long n;
  vector<long long> node, lazy;

 public:
  LazySegmentTree(vector<long long> v) {
    long long sz = (long long)v.size();
    n = 1;
    while (n < sz) n *= 2;
    node.resize(2 * n - 1);
    lazy.resize(2 * n - 1, 0);
    for (long long i = 0; i < (sz); i++) node[i + n - 1] = v[i];
    for (long long i = n - 2; i >= 0; i--)
      node[i] = max(node[2 * i + 1], node[2 * i + 2]);
  }
  void eval(long long k, long long l, long long r) {
    if (lazy[k] != 0) {
      node[k] += lazy[k];
      if (r - l > 1) {
        lazy[2 * k + 1] = lazy[k];
        lazy[2 * k + 2] = lazy[k];
      }
      lazy[k] = 0;
    }
  }
  void add(long long a, long long b, long long x, long long k = 0,
           long long l = 0, long long r = -1) {
    if (r < 0) r = n;
    eval(k, l, r);
    if (b <= l || r <= a) return;
    if (a <= l && r <= b) {
      lazy[k] += (r - l) * x;
      eval(k, l, r);
    } else {
      add(a, b, x, 2 * k + 1, l, (l + r) / 2);
      add(a, b, x, 2 * k + 2, (l + r) / 2, r);
      node[k] = max(node[2 * k + 1], node[2 * k + 2]);
    }
  }
  long long getmax(long long a, long long b, long long k = 0, long long l = 0,
                   long long r = -1) {
    if (r < 0) r = n;
    if (b <= l || r <= a) return 0;
    eval(k, l, r);
    if (a <= l && r <= b) return node[k];
    long long vl = getmax(a, b, 2 * k + 1, l, (l + r) / 2);
    long long vr = getmax(a, b, 2 * k + 2, (l + r) / 2, r);
    return max(vl, vr);
  }
};
const long long mod = 1e9 + 7;
int main() {
  long long n, k;
  cin >> n >> k;
  vector<long long> a(n), dp(300001);
  for (long long i = 0; i < (n); i++) {
    cin >> a[i];
  }
  LazySegmentTree seg = LazySegmentTree(dp);
  for (long long i = 0; i < (n); i++) {
    long long l = max(0LL, a[i] - k);
    long long r = min(30000LL, a[i] + k) + 1;
    long long val = seg.getmax(l, r);
    val++;
    long long v = seg.getmax(a[i], a[i] + 1);
    seg.add(a[i], a[i] + 1, val - v);
  }
  long long ans = 0;
  for (long long i = 0; i < (300001); i++) {
    ans = max(ans, seg.getmax(i, i + 1));
  }
  cout << ans << '\n';
  return 0;
}
