#include <bits/stdc++.h>
using namespace std;
int a[300005];
int st[3000005];
void update(int n, int s, int e, int i, int val) {
  if (s == e)
    st[n] = max(st[n], val);
  else {
    int mid = (s + e) / 2;
    if (i <= mid)
      update(n + n, s, mid, i, val);
    else
      update(n + n + 1, mid + 1, e, i, val);
    st[n] = max(st[2 * n], st[2 * n + 1]);
  }
}
int query(int n, int s, int e, int l, int r) {
  if (s > r || l > e) return 0;
  if (l <= s && e <= r) return st[n];
  int mid = (s + e) / 2;
  int d = max(query(n + n, s, mid, l, r), query(n + n + 1, mid + 1, e, l, r));
  return d;
}
int dp[300005];
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    dp[i] = query(1, 0, 12, max(0, a[i] - k), min(300000, a[i] + k)) + 1;
    update(1, 0, 12, a[i], dp[i]);
    ans = max(ans, dp[i]);
  }
  printf("%d\n", ans);
}
