#include <bits/stdc++.h>
using namespace std;
long long int power(long long int x, long long int y, long long int m) {
  if (y == 0) return 1;
  long long int p = power(x, y / 2, m) % m;
  p = (p * p) % m;
  return (y % 2 == 0) ? p : (x * p) % m;
}
long long int nCr(long long int n, long long int r, long long int m) {
  if (r > n) return 0;
  long long int a = 1, b = 1, i;
  for (i = 0; i < r; i++) {
    a = (a * n) % m;
    --n;
  }
  while (r) {
    b = (b * r) % m;
    --r;
  }
  return (a * power(b, m - 2, m)) % m;
}
vector<int> tree, v, t;
void update(int l, int r, int index, int cindex) {
  if (l == r) {
    tree[index] = t[l];
    return;
  }
  int mid = (l + r) / 2;
  if (cindex <= mid)
    update(l, mid, 2 * index + 1, cindex);
  else
    update(mid + 1, r, 2 * index + 2, cindex);
  tree[index] = max(tree[index * 2 + 1], tree[index * 2 + 2]);
}
int find(int l, int r, int tl, int tr, int index) {
  if (tl > tr) {
    return 0;
  }
  if (tl == l && tr == r) {
    return tree[index];
  }
  int mid = (l + r) / 2;
  int t1 = find(l, mid, tl, min(tr, mid), 2 * index + 1);
  int t2 = find(mid + 1, r, max(tl, mid + 1), tr, 2 * index + 2);
  return max(t1, t2);
}
void solve() {
  int n, k;
  cin >> n >> k;
  v = t = vector<int>(n);
  tree = vector<int>(4 * (300001));
  for (int i = 0; i < n; ++i) {
    cin >> v[i];
    int temp = find(0, 300000, max(v[i] - k, 0), min(v[i] + k, 300000), 0);
    t[v[i]] = temp + 1;
    update(0, 300000, 0, v[i]);
  }
  cout << tree[0] << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  solve();
  return 0;
}
