#include <bits/stdc++.h>
using namespace std;
int N, K, A[300005];
const int M = 1 << 19;
int ST[M * 2];
void CHANGE(int k, int v) {
  ST[M + k] = v;
  int p = (M + k) / 2;
  while (p > 1) {
    ST[p] = max(ST[p * 2], ST[p * 2 + 1]);
    p /= 2;
  }
}
int Q(int a, int b, int l = 0, int r = M - 1, int k = 1) {
  if (b < l || r < a) {
    return 0;
  }
  if (a <= l && r <= b) {
    return ST[k];
  }
  int tmp1 = Q(a, b, l, (l + r) / 2, k * 2);
  int tmp2 = Q(a, b, (l + r) / 2 + 1, r, k * 2 + 1);
  if (tmp1 >= tmp2) {
    return tmp1;
  }
  return tmp2;
}
int main(void) {
  cin >> N >> K;
  for (int i = 1; i <= N; i++) {
    cin >> A[i];
  }
  for (int i = 1; i <= N; i++) {
    int l = A[i] - K;
    int r = A[i] + K;
    int ret = Q(l, r);
    CHANGE(A[i], ret + 1);
  }
  cout << Q(1, M) << endl;
  return 0;
}
