#include <bits/stdc++.h>
using namespace std;
long long n, m, a, b, c, k, temp, x, y;
const int MAXN = 1e5 + 11, mod = 1e9 + 7;
long long max(long long a, long long b) { return ((a > b) ? a : b); }
long long min(long long a, long long b) { return ((a > b) ? b : a); }
vector<long long> read(int n) {
  vector<long long> v(n);
  for (int i = 0; i < v.size(); i++) cin >> v[i];
  return v;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int tree[4 * MAXN];
int qfst(int l, int r) {
  int res = 0;
  for (l += 300001, r += 300001; l < r; l >>= 1, r >>= 1) {
    if (l & 1) res = max(tree[l++], res);
    if (r & 1) res = max(tree[--r], res);
  }
  return res;
}
void modify(int p, int value) {
  for (tree[p += 300001] = value; p > 1; p >>= 1)
    tree[p >> 1] = max(tree[p], tree[p ^ 1]);
}
void sol(void) {
  cin >> n >> k;
  vector<long long> v = read(n);
  for (int i = 0; i < n; i++) {
    int mx = qfst(v[i], v[i] + 1);
    int ending = qfst(max(0, v[i] - k), min(v[i] + k + 1, 300001)) + 1;
    modify(v[i], max(mx, ending));
  }
  cout << qfst(0, 300001);
  return;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int test = 1;
  for (int i = 1; i <= test; i++) sol();
}
