#include <bits/stdc++.h>
using namespace std;
int ans[300005];
int st[4 * 3000005];
void consst(int i, int l, int r) {
  if (l == r) {
    st[i] = ans[l];
    return;
  }
  int m = l + r;
  m /= 2;
  consst(2 * i + 1, l, m);
  consst(2 * i + 2, m + 1, r);
  st[i] = max(st[2 * i + 1], st[2 * i + 2]);
}
int ret(int i, int a, int b, int x, int y) {
  if (b < x || y < a) return 0;
  if (x <= a && b <= y) return st[i];
  int m;
  m = a + b;
  m /= 2;
  return max(ret(2 * i + 1, a, m, x, y), ret(2 * i + 2, m + 1, b, x, y));
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, k;
  cin >> n >> k;
  int a[n];
  int i;
  for (i = 0; i < n; i++) cin >> a[i];
  memset(ans, 0, sizeof(ans));
  ans[a[n - 1]] = 1;
  consst(0, 0, 300001);
  for (i = n - 2; i >= 0; i--) {
    int res = ret(0, 0, 300001, max(1, a[i] - k), min(300001, a[i] + k));
    if (ans[a[i]] < res + 1) {
      ans[a[i]] = res + 1;
      consst(0, 0, 300001);
    }
  }
  int answer = 0;
  for (i = 0; i < 300005; i++) {
    answer = max(answer, ans[i]);
  }
  cout << answer << endl;
  return 0;
}
