#include <bits/stdc++.h>
using namespace std;
int n, m, a[300010], res;
inline long long read() {
  char c;
  long long d = 1, f = 0;
  while (c = getchar(), !isdigit(c))
    if (c == '-') d = -1;
  f = (f << 3) + (f << 1) + c - 48;
  while (c = getchar(), isdigit(c)) f = (f << 3) + (f << 1) + c - 48;
  return d * f;
}
struct xds {
  int maxn[6000010 << 2];
  inline int Query(int ql, int qr, int k = 1, int l = 0, int r = 2 * m) {
    if (ql >= l && r <= qr) return maxn[k];
    int mid = l + r >> 1, res = 0;
    if (ql <= mid) res = max(res, Query(ql, qr, k << 1, l, mid));
    if (qr > mid) res = max(res, Query(ql, qr, k << 1 | 1, mid + 1, r));
    return res;
  }
  inline void Modify(int x, int d, int k = 1, int l = 0, int r = 2 * m) {
    if (l == r) {
      maxn[x] = d;
      return;
    }
    int mid = l + r >> 1;
    if (x <= mid)
      Modify(x, d, k << 1, l, mid);
    else
      Modify(x, d, k << 1 | 1, mid + 1, r);
    maxn[k] = max(maxn[k << 1], maxn[k << 1 | 1]);
    return;
  }
} T;
signed main() {
  n = read();
  m = read();
  for (register int i = 1; i <= n; i++) a[i] = read() + m;
  T.Modify(a[1], 1);
  res = 1;
  for (register int i = 2; i <= n; i++) {
    int now = T.Query(a[i] - m, a[i] + m) + 1;
    T.Modify(a[i], now + 1);
    res = max(res, now);
  }
  printf("%d", res);
}
