#include <bits/stdc++.h>
using namespace std;
class SegmentTree {
 public:
  vector<long long int> arr;
  long long int n;
  vector<long long int> tree;
  SegmentTree(long long int size) {
    n = size;
    arr.assign(n + 1, 0);
    tree.resize(4 * n + 1);
  }
  void update(long long int curr, long long int l, long long int r,
              long long int pos, long long int val) {
    if (l == r) {
      tree[curr] = max(tree[curr], val);
      return;
    }
    long long int mid = (l + r) / 2;
    if (pos <= mid) {
      update(curr * 2, l, mid, pos, val);
    } else {
      update(curr * 2 + 1, mid + 1, r, pos, val);
    }
    tree[curr] = max(tree[curr << 1], tree[curr << 1 | 1]);
  }
  long long int query(long long int curr, long long int l, long long int r,
                      long long int i, long long int j) {
    if (j < l || i > r) return 0;
    if (i <= l && r <= j) {
      return tree[curr];
    }
    long long int mid = (l + r) / 2;
    long long int left = query(curr * 2, l, mid, i, j);
    long long int right = query(curr * 2 + 1, mid + 1, r, i, j);
    return max(left, right);
  }
};
void solve() {
  long long int n, k;
  cin >> n >> k;
  vector<long long int> arr(n + 1);
  for (long long int i = 1; i <= n; i++) {
    cin >> arr[i];
  }
  SegmentTree tree(1e7);
  vector<long long int> dp(n + 1);
  for (long long int i = 1; i <= n; i++) {
    long long int left = max(0LL, arr[i] - k);
    long long int right = arr[i] + k;
    long long int maxx = tree.query(1, 1, (1e7) - 1, left, right);
    ;
    dp[i] = 1 + maxx;
    tree.update(1, 1, (1e7) - 1, arr[i], dp[i]);
  };
  cout << dp[n] << "\n";
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
