#include <bits/stdc++.h>
using namespace std;
constexpr long long INF = 1999999999999999997;
int a[300005];
int tree[4 * 300005];
int n, k;
void update(int node, int s, int e, int idx, int val) {
  if (s == e) {
    tree[node] = val;
  } else {
    int mid = (s + e) / 2;
    if (idx > mid) {
      update(2 * node + 1, mid + 1, e, idx, val);
    } else {
      update(2 * node, s, mid, idx, val);
    }
    tree[node] = max(tree[2 * node], tree[2 * node + 1]);
  }
}
int query(int node, int s, int e, int l, int r) {
  if (r < s || l > e) return INT_MIN;
  if (s >= l && e <= r) return tree[node];
  int mid = (s + e) / 2;
  int q1 = query(2 * node, s, mid, l, r);
  int q2 = query(2 * node + 1, mid + 1, e, l, r);
  return max(q1, q2);
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    int l, r;
    l = max(0, a[i] - k);
    r = min(a[i] + k, 300000);
    int x = query(1, 0, n - 1, l + 1, r + 1);
    update(1, 0, n - 1, a[i] + 1, x + 1);
    ans = max(ans, x + 1);
  }
  cout << ans << endl;
}
