#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vin = vector<int>;
using vll = vector<long long>;
using vvin = vector<vector<int>>;
using vvll = vector<vector<long long>>;
using vstr = vector<string>;
using vvstr = vector<vector<string>>;
using vch = vector<char>;
using vvch = vector<vector<char>>;
using vbo = vector<bool>;
using vvbo = vector<vector<bool>>;
using vpii = vector<pair<int, int>>;
using pqsin = priority_queue<int, vector<int>, greater<int>>;
const ll inf = 1e9 + 7;
const ll INF = 1e18;
const ll mod = 99824453;
const int MAX_N = 1 << 20;
int N;
vll dat(2 * MAX_N);
void init(int N_) {
  N = 1;
  while (N < N_) N *= 2;
}
void update(int i, ll x) {
  i += N - 1;
  dat[i] = x;
  while (i > 0) {
    i = (i - 1) / 2;
    dat[i] = max(dat[2 * i + 1], dat[2 * i + 2]);
  }
}
ll getmax(int a, int b, int k = 0, int l = 0, int r = -1) {
  if (r < 0) r = N;
  if (r <= a || b <= l) return -1;
  if (a <= l && r <= b)
    return dat[k];
  else {
    ll chl = getmax(a, b, 2 * k + 1, l, (l + r) / 2);
    ll chr = getmax(a, b, 2 * k + 2, (l + r) / 2, r);
    return max(chl, chr);
  }
}
int main() {
  const int c = 300010;
  init(c);
  int n, k;
  cin >> n >> k;
  int a, x, y = 0;
  for (int i = 0; i < (int)(n); i++) {
    cin >> a;
    x = getmax(max(a - k, 0), min(a + k + 1, c));
    update(a, max(x + 1, y));
    y = max(y, x + 1);
  }
  cout << y << endl;
}
