#include <bits/stdc++.h>
using namespace std;
inline int read() {
  char ch = getchar();
  int x = 0, cf = 1;
  while (ch < '0' || ch > '9') {
    if (ch == '-') cf = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = (x << 3) + (x << 1) + (ch ^ 48);
    ch = getchar();
  }
  if (cf < 0)
    return -x;
  else
    return x;
}
int num[1200001];
int lc(int p) { return p << 1; }
int rc(int p) { return p << 1 | 1; }
void pushup(int p) { num[p] = max(num[lc(p)], num[rc(p)]); }
void change(int L, int R, int l, int r, int p, int x) {
  if (L <= l && r <= R) {
    num[p] = x;
    return;
  }
  int mid = (l + r) >> 1;
  if (L <= mid) change(L, R, l, mid, lc(p), x);
  if (R >= mid + 1) change(L, R, mid + 1, r, rc(p), x);
  pushup(p);
}
int Q(int L, int R, int l, int r, int p) {
  if (L <= l && r <= R) {
    return num[p];
  }
  int ans = -1;
  int mid = (l + r) >> 1;
  if (L <= mid) ans = max(ans, Q(L, R, l, mid, lc(p)));
  if (R >= mid + 1) ans = max(ans, Q(L, R, mid + 1, r, rc(p)));
  return ans;
}
int qwq[300010];
int main() {
  int n, k;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> qwq[i];
  }
  int ans = 1;
  for (int i = 1; i <= n; i++) {
    int l = max(1, qwq[i] - k);
    int r = min(300000, qwq[i] + k);
    int qaq = Q(l, r, 1, 300000, 1) + 1;
    ans = max(ans, qaq);
    change(qwq[i], qwq[i], 1, 300000, 1, qaq);
  }
  cout << ans << endl;
  return 0;
  cout << "UUZ ate it." << endl;
}
