#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-9;
const double PI = acos(-1.0);
template <typename T>
inline T sq(T a) {
  return a * a;
}
template <typename T1, typename T2>
inline pair<T1, T2> mp(T1 a, T2 b) {
  return make_pair(a, b);
}
template <typename T1, typename T2>
inline T1 safeMod(T1 a, T2 m) {
  return (a % m + m) % m;
}
template <typename T1, typename T2>
inline bool isEq(T1 a, T2 b) {
  return abs(a - b) < EPS;
}
template <typename T1, typename T2, typename T3>
inline bool isEq(T1 a, T2 b, T3 eps) {
  return abs(a - b) < eps;
}
template <typename T>
inline bool isKthBitOn(T n, int k) {
  assert(n <= numeric_limits<T>::max());
  assert(k <= numeric_limits<T>::digits);
  T ONE = 1;
  return bool((n & (ONE << k)));
}
template <typename T>
inline void setKthBit(T& n, int k) {
  assert(n <= numeric_limits<T>::max());
  assert(k <= numeric_limits<T>::digits);
  T ONE = 1;
  n = (n | (ONE << k));
}
const int oo = 0x3f3f3f3f;
const int MAX = 200010;
const int MOD = 1000000007;
const int precision = 10;
int tree[4 * 300000];
void update(int n, int l, int r, int p, int v) {
  if (l == r) {
    if (l == p) tree[n] = v;
    return;
  }
  int m = (l + r) / 2;
  update(2 * n, l, m, p, v);
  update(2 * n + 1, m + 1, r, p, v);
  tree[n] = ((tree[n << 1]) > (tree[(n << 1) | 1])) ? (tree[n << 1])
                                                    : (tree[(n << 1) | 1]);
}
int query(int n, int l, int r, int ql, int qr) {
  if (r < ql || qr < l) return 0;
  if (ql <= l && r <= qr) return tree[n];
  int m = (l + r) / 2;
  return ((query(n << 1, l, m, ql, qr)) >
          (query((n << 1) | 1, m + 1, r, ql, qr)))
             ? (query(n << 1, l, m, ql, qr))
             : (query((n << 1) | 1, m + 1, r, ql, qr));
}
int v[300005];
void solve(int kas) {
  int n, k;
  scanf("%d %d", &n, &k);
  for (int i = 0; i < n; i++) scanf("%d", &v[i]);
  int mx = 0;
  for (int i = n - 1; i >= 0; i--) {
    int l = ((0) > (v[i] - k)) ? (0) : (v[i] - k);
    int r = ((300000) < (v[i] + k)) ? (300000) : (v[i] + k);
    int mm = query(1, 0, 300000, l, r);
    mx = ((mx) > (1 + mm)) ? (mx) : (1 + mm);
    update(1, 0, 300000, v[i], mx);
  }
  printf("%d\n", mx);
}
int main() {
  int tc = 1;
  for (int _ = 1; _ <= tc; _++) {
    solve(_);
  }
  return 0;
}
