#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int d4x[4] = {-1, 0, 1, 0};
const int d4y[4] = {0, 1, 0, -1};
const int MOD = 998244353;
const ll INF = 1e18 + 7;
ll powmod(ll base, ll exp, const ll MOD) {
  ll ans = 1;
  while (exp) {
    if (exp & 1) ans = (ans * base) % MOD;
    base = (base * base) % MOD;
    exp >>= 1;
  }
  return ans;
}
ll modInverse(ll n, const ll p) { return powmod(n, p - 2, p); }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a, b); }
const int MAXN = 3e5;
int Node[4 * MAXN + 100];
int n, k;
void update(int pos, int val, int i = 0, int l = 1, int r = MAXN) {
  if (l == r) {
    Node[i] = val;
    return;
  }
  int mid = (l + r) / 2;
  if (pos <= mid)
    update(pos, val, 2 * i + 1, l, mid);
  else
    update(pos, val, 2 * i + 2, mid + 1, r);
  Node[i] = max(Node[2 * i + 1], Node[2 * i + 2]);
}
int getmax(int l1, int r1, int i = 0, int l2 = 1, int r2 = MAXN) {
  if (l2 > r1 || r2 < l1) return 0;
  if (l2 >= l1 && r2 <= r1) return Node[i];
  int mid = (l2 + r2) / 2;
  int a = getmax(l1, r1, 2 * i + 1, l2, mid);
  int b = getmax(l1, r1, 2 * i + 2, mid + 1, r2);
  return Node[i] = max(a, b);
}
void test_case() {
  cin >> n >> k;
  vector<int> a(n);
  for (int i = 0; i < (n); ++i) cin >> a[i];
  for (int i = 0; i < n; ++i) {
    int l = max(1, a[i] - k);
    int r = min(MAXN, a[i] + k);
    int mx = getmax(l, r);
    update(a[i], max(getmax(a[i], a[i]), mx + 1));
  }
  cout << getmax(1, MAXN);
}
int main() {
  {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
  };
  test_case();
  return 0;
}
