#include <bits/stdc++.h>
using namespace std;
const long double eps = 0.0000000001;
const int MOD = 998244353;
const int INF = 1000055555;
const long long LLINF = 1223372000000000555;
const int N = 2250555;
const int M = 2522;
int t[N];
int a[N];
int get(int v, int tl, int tr, int l, int r) {
  if (tl >= l && tr <= r) return t[v];
  if (tl > r || tr < l) return 0;
  int tm = (tl + tr) >> 1;
  return max(get(v + v, tl, tm, l, r), get(v + v + 1, tm + 1, tr, l, r));
}
void update(int v, int tl, int tr, int pos, int val) {
  if (tl == tr) {
    t[v] = val;
    return;
  }
  int tm = (tl + tr) >> 1;
  if (pos <= tm)
    update(v + v, tl, tm, pos, val);
  else
    update(v + v + 1, tm + 1, tr, pos, val);
  t[v] = max(t[v + v], t[v + v + 1]);
}
void solve() {
  int n, k;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  int A = 300000;
  for (int i = 1; i <= n; i++) {
    int l = max(0, a[i] - k), r = min(A, a[i] + k);
    int dp = get(1, 1, A, l, r) + 1;
    update(1, 1, A, a[i], dp);
    if (i == n) {
      cout << dp;
      return;
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  int T = 1;
  while (T--) {
    solve();
  }
  return 0;
}
