#include <bits/stdc++.h>
using namespace std;
vector<int> arr, st;
int query(int node, int l, int r, int ll, int rl) {
  if (l <= ll && r >= rl) return st[node];
  if (r < ll || l > rl) return 0;
  int mid = ll + (rl - ll) / 2;
  int left = query(2 * node + 1, l, r, ll, mid);
  int right = query(2 * node + 2, l, r, mid + 1, rl);
  return max(left, right);
}
int update(int node, int i, int v, int ll, int rl) {
  if (i < ll || i > rl) return st[node];
  if (ll == rl) {
    st[node] = v;
    return st[node];
  }
  int mid = ll + (rl - ll) / 2;
  if (ll <= i && i <= mid)
    int left = update(2 * node + 1, i, v, ll, mid);
  else
    int right = update(2 * node + 2, i, v, mid + 1, rl);
  st[node] = max(st[2 * node + 1], st[2 * node + 2]);
  return st[node];
}
int main() {
  int n, k;
  cin >> n >> k;
  arr.resize(n);
  int size = 1;
  while (size < 3e5) size *= 2;
  st.assign(2 * size, 0);
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    int l = max(0, arr[i] - k);
    int r = min(2 * size - 1, arr[i] + k);
    int v = query(0, l, r, 0, n - 1);
    update(0, arr[i], v + 1, 0, n - 1);
  }
  cout << st[0] << '\n';
}
