#include <bits/stdc++.h>
using namespace std;
const long long INF = 0;
long long n, node[100000000];
void init(long long N_) {
  n = 1;
  while (n < N_) n *= 2;
  for (long long i = 0; i < 2 * n - 1; i++) node[i] = INF;
}
void update(long long a, long long x) {
  a += n - 1;
  node[a] = x;
  while (a > 0) {
    a = (a - 1) / 2;
    node[a] = max(node[2 * a + 1], node[2 * a + 2]);
  }
}
long long query(long long a, long long b, long long k, long long l,
                long long r) {
  if (b <= l || r <= a) return INF;
  if (a <= l && r <= b) return node[k];
  long long vl = query(a, b, 2 * k + 1, l, (l + r) / 2);
  long long vr = query(a, b, 2 * k + 2, (l + r) / 2, r);
  return max(vl, vr);
}
int main(void) {
  long long N, K;
  cin >> N >> K;
  vector<long long> A(N);
  for (long long i = 0; i < N; i++) {
    cin >> A[i];
  }
  init(300001);
  for (long long i = 0; i < N; i++) {
    long long premin = max((long long)0, A[i] - K);
    long long premax = min((long long)300000, A[i] + K);
    long long num = query(premin - 1, premax + 1, 0, 0, n);
    update(A[i], num + 1);
  }
  long long ans = query(-1, n - 1, 0, 0, n);
  cout << ans << endl;
}
