#include <bits/stdc++.h>
using namespace std;
const int maxn = 300050;
int lim = 300001;
int s[maxn << 2];
int a[maxn], dp[maxn];
int n, k;
void pushup(int x) { s[x] = max(s[x << 1], s[x << 1 | 1]); }
void update(int x, int l, int r, int k, int val) {
  if (l == r) {
    s[x] = max(s[x], val);
    return;
  }
  int mid = (l + r) >> 1;
  if (mid >= k) update(x << 1, l, mid, k, val);
  if (mid < k) update(x << 1 | 1, mid + 1, r, k, val);
  pushup(x);
}
int query(int x, int l, int r, int L, int R) {
  if (L <= l && r <= R) return s[x];
  int mid = (l + r) >> 1, res = 0;
  if (mid >= L) res = max(res, query(x << 1, l, mid, L, R));
  if (mid < R) res = max(res, query(x << 1 | 1, mid + 1, r, L, R));
  return res;
}
void solve() {
  scanf("%d %d", &n, &k);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    a[i]++;
  }
  dp[1] = 1;
  update(1, 1, n, a[1], dp[1]);
  for (int i = 2; i <= n; i++) {
    int l = max(a[i] - k, 1), r = min(a[i] + k, lim);
    dp[i] = query(1, 1, lim, l, r) + 1;
    update(1, 1, lim, a[i], dp[i]);
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) ans = max(ans, dp[i]);
  printf("%d\n", ans);
}
int main() {
  solve();
  return 0;
}
