#include <bits/stdc++.h>
using namespace std;
void parseArray(long long* A, long long n) {
  for (long long K = 0; K < n; K++) {
    cin >> A[K];
  }
}
long long modInverse(long long a, long long b) {
  return 1 < a ? b - modInverse(b % a, a) * b / a : 1;
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); }
long double dist(long double x, long double y, long double a, long double b) {
  return sqrt((x - a) * (x - a) + (y - b) * (y - b));
}
void debug(long long* a, long long n) {
  for (long long k = 0; k < n; k++) {
    cerr << a[k] << " ";
  }
  cout << "\n";
}
long long n, t[4 * 300003];
int segTreeOp(int a, int b) { return max(a, b); }
int query(int v, int tl, int tr, int l, int r) {
  if (l > r) return 0;
  if (l == tl && r == tr) return t[v];
  int tm = (tl + tr) / 2;
  return segTreeOp(query(v * 2, tl, tm, l, min(r, tm)),
                   query(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r));
}
void update(int v, int tl, int tr, int pos, int new_val) {
  if (tl == tr) {
    t[v] = new_val;
  } else {
    int tm = (tl + tr) / 2;
    if (pos <= tm)
      update(v * 2, tl, tm, pos, new_val);
    else
      update(v * 2 + 1, tm + 1, tr, pos, new_val);
    t[v] = segTreeOp(t[v * 2], t[v * 2 + 1]);
  }
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  ;
  memset(t, 0, sizeof t);
  long long m;
  cin >> n >> m;
  long long a[n];
  parseArray(a, n);
  long long ans = 0;
  for (long long e : a) {
    ans =
        max(ans, 1ll + query(1, 0, n - 1, max(0ll, e - m), min(n - 1, e + m)));
    update(1, 0, n - 1, e,
           query(1, 0, n - 1, max(0ll, e - m), min(n - 1, e + m)) + 1);
  }
  cout << ans << endl;
  return 0;
}
