#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 5;
const int mod = 998244353;
const int infi = (2e9 + 69);
const long long infy = (2e16 + 69);
const int base = 311;
const long long MM = 7ll * mod * mod;
const int addition = 1e5;
const double eps = 1e-8;
const string numd[10] = {"1110111", "0010010", "1011101", "1011011", "0111010",
                         "1101011", "1101111", "1010010", "1111111", "1111011"};
const int dx[4] = {1, -1, 0, 0};
const int dy[4] = {0, 0, 1, -1};
const double pi = 3.14159265358980;
const string P1 = "T";
const string P2 = "HL";
const string spmcode =
    "My power does not end. Ask for aid and you will receive it.\n";
template <typename Num>
void maximize(Num &x, Num y) {
  x = mx(x, y);
}
template <typename Num>
void minimize(Num &x, Num y) {
  x = min(x, y);
}
void exit_with_runtime() {
  double x = 1.0 * clock() / CLOCKS_PER_SEC;
  cerr << "\n\n---------------------\nTime elapsed: " << x << " s.\n\n";
  exit(0);
}
void decorate() {
  cerr << "KienNguyen246\n";
  chrono::system_clock::time_point today = chrono::system_clock::now();
  time_t tt = chrono::system_clock::to_time_t(today);
  cerr << ctime(&tt);
  cerr << "\nProcessing...\n\n";
}
int n, a[maxn], tree[maxn << 2], m, k;
void Upd(int nod, int l, int r, int u, int w) {
  if (l > u || r < u) return;
  if (l == r) {
    tree[nod] = w;
    return;
  }
  int mid = (l + r) / 2;
  Upd(nod * 2, l, mid, u, w);
  Upd(nod * 2 + 1, mid + 1, r, u, w);
  tree[nod] = max(tree[nod * 2], tree[nod * 2 + 1]);
}
int Max(int nod, int l, int r, int u, int v) {
  if (l > v || r < u) return 0;
  if (l >= u && r <= v) return tree[nod];
  int mid = (l + r) / 2;
  int L = Max(nod * 2, l, mid, u, v);
  int R = Max(nod * 2 + 1, mid + 1, r, u, v);
  return max(L, R);
}
int Main_Process() {
  cin >> n >> k;
  for (int i = 1; i <= n; i++) cin >> a[i], m = max(m, a[i]);
  for (int i = 1; i <= n; i++) {
    int val = Max(1, 1, m, max(a[i] - k, 1), min(a[i] + k, m));
    Upd(1, 1, m, a[i], val + 1);
  }
  cout << Max(1, 1, m, 1, m);
  return 0;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  decorate();
  int test = 1;
  cerr << spmcode << "\n";
  while (test--) Main_Process();
  exit_with_runtime();
}
