#include <bits/stdc++.h>
using namespace std;
int N, K, tree[300010], A[300010], arr[300010];
void build(int node, int start, int end) {
  if (start == end) {
    tree[node] = A[start];
  } else {
    int mid = (start + end) / 2;
    build(2 * node, start, mid);
    build(2 * node + 1, mid + 1, end);
    tree[node] = max(tree[2 * node], tree[2 * node + 1]);
  }
}
void update(int node, int start, int end, int idx, int val) {
  if (start == end) {
    A[idx] += val;
    tree[node] += val;
  } else {
    int mid = (start + end) / 2;
    if (start <= idx and idx <= mid) {
      update(2 * node, start, mid, idx, val);
    } else {
      update(2 * node + 1, mid + 1, end, idx, val);
    }
    tree[node] = max(tree[2 * node], tree[2 * node + 1]);
  }
}
int query(int node, int start, int end, int l, int r) {
  if (r < start or end < l) {
    return 0;
  }
  if (l <= start and end <= r) {
    return tree[node];
  }
  int mid = (start + end) / 2;
  int p1 = query(2 * node, start, mid, l, r);
  int p2 = query(2 * node + 1, mid + 1, end, l, r);
  return max(p1, p2);
}
void Input() {
  cin >> N >> K;
  for (int i = 0; i < N; i++) {
    cin >> arr[i];
  }
}
void Solve() {
  int maxim = 0;
  for (int i = 0; i < N; i++) {
    int curr = arr[i], currsum = 0;
    currsum = query(1, 0, 300000, max(curr - K, 0), min(curr + K, 300000)) + 1;
    maxim = max(maxim, currsum);
    update(1, 0, 300000, arr[i], currsum);
  }
  cout << maxim << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  Input();
  Solve();
}
