#include <bits/stdc++.h>
using namespace std;
struct Data {
  long long val, idx;
};
long long a[100010], c[100010], q[100010];
long long Maxn[100010 * 4];
Data b[100010];
int n;
long long ans, d;
bool cmp(Data x, Data y) { return (x.val < y.val); }
void update(int o, int l, int r, int x, long long v) {
  if (l == x && r == x) {
    Maxn[o] = v;
    return;
  }
  int mid = (l + r) >> 1;
  if (x <= mid) update(o * 2, l, mid, x, v);
  if (x > mid) update(o * 2 + 1, mid + 1, r, x, v);
  Maxn[o] = max(Maxn[o * 2], Maxn[o * 2 + 1]);
}
void query(int o, int l, int r, int x, int y) {
  if (x <= l && r <= y) {
    ans = max(Maxn[o], ans);
    return;
  }
  int mid = (l + r) >> 1;
  if (x <= mid) query(o * 2, l, mid, x, y);
  if (y > mid) query(o * 2 + 1, mid + 1, r, x, y);
}
int main() {
  cin >> n >> d;
  memset(Maxn, 0, sizeof(Maxn));
  memset(q, 0, sizeof(q));
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    b[i].val = a[i];
    b[i].idx = i;
  }
  sort(b, b + n, cmp);
  for (int i = 0; i < n; i++) {
    c[i] = b[i].val;
    q[b[i].idx] = i;
  }
  long long tot = 1;
  for (int i = 0; i < n; i++) {
    long long l = a[i] - d, r = a[i] + d;
    int ll = lower_bound(c, c + n, l) - c;
    int rr = upper_bound(c, c + n, r) - c - 1;
    ans = 0;
    query(1, 0, n - 1, ll, rr);
    if (ans == 0)
      update(1, 0, n - 1, q[i], 1);
    else {
      update(1, 0, n - 1, q[i], ans + 1);
      if (ans + 1 > tot) tot = ans + 1;
    }
  }
  cout << tot << endl;
  return 0;
}
