#include <bits/stdc++.h>
using namespace std;
const int N = 300010;
int n, k, arr[N], tree[N << 2], dp[N];
void update(int node, int l, int r, int i, int v) {
  if (r < i || l > i) return;
  if (i <= l && r <= i) {
    tree[node] += v;
    return;
  }
  int mid = (l + r) >> 1;
  update(node << 1, l, mid, i, v);
  update(node << 1 | 1, mid + 1, r, i, v);
  tree[node] = max(tree[node << 1], tree[node << 1 | 1]);
}
int query(int node, int l, int r, int i, int j) {
  if (r < i || l > j) return 0;
  if (i <= l && r <= j) {
    return tree[node];
  }
  int mid = (l + r) >> 1;
  return max(query(node << 1, l, mid, i, j),
             query(node << 1 | 1, mid + 1, r, i, j));
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> k;
  for (int i = 1; i <= n; ++i) cin >> arr[i];
  for (int i = 1; i <= n; ++i) {
    dp[i] =
        query(1, 1, N - 10, max(1, arr[i] - k), min(N - 10, arr[i] + k)) + 1;
    update(1, 1, N - 10, arr[i], dp[i]);
  }
  int ans = 0;
  for (int i = 1; i <= n; ++i) ans = max(ans, dp[i]);
  cout << ans << '\n';
}
