#include <bits/stdc++.h>
using namespace std;
int mx = 300005;
int s, k;
vector<int> segtree;
int update(int x) {
  while (x) {
    if (2 * x + 1 <= k) {
      segtree[x] = max(segtree[2 * x], segtree[2 * x + 1]);
    }
    x /= 2;
  }
}
int count(int x, int lx, int rx, int l, int r) {
  if (lx > r || rx < l) {
    return 0;
  } else if (lx >= l && rx <= r) {
    return segtree[x];
  } else {
    int mid = lx + rx;
    mid /= 2;
    int a1 = count(2 * x, lx, mid, l, r);
    int a2 = count(2 * x + 1, mid + 1, rx, l, r);
    return max(a1, a2);
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, dif;
  cin >> n >> dif;
  for (; k <= 30; k++) {
    if ((1 << k) >= mx) break;
  }
  s = 1 << k;
  k++;
  k = 1 << k;
  segtree.resize(k + 1, 0);
  int arr[n + 1];
  for (int i = 1; i <= n; i++) {
    cin >> arr[i];
    arr[i]++;
  }
  for (int i = 1; i <= n; i++) {
    int l = max(0, arr[i] - dif);
    int r = min(mx, arr[i] + dif);
    int x = count(1, 1, s, l, r);
    segtree[s - 1 + arr[i]] = x + 1;
    update(s - 1 + arr[i]);
  }
  cout << segtree[1];
  return 0;
}
