#include <bits/stdc++.h>
class segment_tree {
 private:
  int mx[1200005];
  inline int max(int a, int b) { return a > b ? a : b; }
  inline void update(int k) { mx[k] = max(mx[k << 1], mx[k << 1 | 1]); }

 public:
  void change(int k, int l, int r, int pos, int x) {
    if (l == r && r == pos) {
      mx[k] = x;
      return;
    }
    int mid = l + r >> 1;
    if (mid >= pos)
      change(k << 1, l, mid, pos, x);
    else
      change(k << 1 | 1, mid + 1, r, pos, x);
    update(k);
  }
  int query(int k, int l, int r, int x, int y) {
    if (x <= 0) x = 1;
    if (y > 300000) y = 300000;
    if (l >= x && r <= y) return mx[k];
    int mid = l + r >> 1, res = 0;
    if (mid >= x) res = max(res, query(k << 1, l, mid, x, y));
    if (mid < y) res = max(res, query(k << 1 | 1, mid + 1, r, x, y));
    return res;
  }
} t;
int n, k, a[300005];
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
  for (int i = 1; i <= n; ++i)
    t.change(1, 1, 300000, a[i], t.query(1, 1, 300000, a[i] - k, a[i] + k) + 1);
  printf("%d", t.query(1, 1, 300000, 1, 300000));
}
