#include <bits/stdc++.h>
template <class T>
T gcd(T a, T b) {
  T r;
  while (b != 0) {
    r = a % b;
    a = b;
    b = r;
  }
  return a;
}
template <class T>
T lcm(T a, T b) {
  return a / gcd(a, b) * b;
}
using namespace std;
int prime(int n) {
  for (int i = 2; i * i <= n; i++)
    if (n % i == 0) return 0;
  return 1;
}
void InitPrime() {
  int pr[300005];
  fill(pr + 1, pr + 1001, 1);
  pr[1] = 0;
  for (int i = 2; i <= 1000; i++)
    if (pr[i])
      for (int j = i + i; j <= 1000; j += i) pr[j] = 0;
}
void AddMOD(int &x, int y) {
  x += y;
  if (x >= 1000007) x -= 1000007;
}
long long tinh(long long a, long long b, long long c) {
  if (b == 1) return a % c;
  long long x = tinh(a, b / 2, c);
  long long y = (1ll * x * x) % c;
  if (b % 2 != 0) y = (1ll * y * a) % c;
  return y;
}
long long tinh2(long long a, long long n, long long mod = 1000007) {
  a = a < 0 ? (mod - (-a) % mod) : (a % mod);
  long long r = 1;
  while (n) {
    if (n & 1) r = r * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return r;
}
long long n, k, a[4 * 300005], t[4 * 300005], dp[4 * 300005];
void init(int l, int r, int id) {
  if (l == r) {
    t[id] = a[l];
    return;
  }
  int mid = (l + r) >> 1;
  init(l, mid, id * 2);
  init(mid + 1, r, id * 2 + 1);
  t[id] = max(t[id * 2], t[id * 2] + 1);
}
int get_max(int l, int r, int id, int u, int v) {
  if (l > v || r < u) return -1000007;
  if (l >= u && r <= v) return t[id];
  int mid = (l + r) >> 1;
  long long m1 = get_max(l, mid, id * 2, u, v);
  long long m2 = get_max(mid + 1, r, id * 2 + 1, u, v);
  return max(m1, m2);
}
void update(int l, int r, int id, int x, int val) {
  if (l > r || l > x || r < x) return;
  if (l == r) {
    t[id] = max(t[id], (long long)val);
    return;
  }
  int mid = (l + r) >> 1;
  if (x <= mid)
    update(l, mid, id * 2, x, val);
  else
    update(mid + 1, r, id * 2 + 1, x, val);
  t[id] = max(t[id * 2], t[id * 2 + 1]);
}
int main() {
  int base = 3000005;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) cin >> a[i], a[i] += base;
  for (int i = 1; i <= n; i++) {
    int l = a[i] - k, r = a[i] + k;
    long long Max = get_max(1, 1000007, 1, l, r);
    dp[i] = max(dp[i], Max + 1);
    update(1, 1000007, 1, a[i], dp[i]);
  }
  cerr << endl;
  cout << dp[n];
}
