#include <bits/stdc++.h>
using namespace std;
const long long mod = 998244353;
const int N = 300006;
const long long INF = 1e18;
struct seg_tree {
  vector<int> val;
  int B;
  void init(int n) {
    B = 1;
    while (B < n) {
      B *= 2;
      val.resize(B * 2);
    }
  }
  void upd(int node, int l, int r, int pos, int x) {
    if (l + 1 == r) {
      val[node] = max(val[node], x);
      return;
    }
    if (l > pos || r <= pos) return;
    int mid = (l + r) / 2;
    upd(node * 2 + 1, l, mid, pos, x);
    upd(node * 2 + 2, mid, r, pos, x);
    val[node] = max(val[node * 2 + 1], val[node * 2 + 2]);
  }
  void upd(int pos, int x) { upd(0, 0, B, pos, x); }
  int ask(int node, int l, int r, int lf, int rg) {
    if (l >= lf && r <= rg) {
      return val[node];
    }
    if (l >= rg || r <= lf) return 0;
    int mid = (l + r) / 2;
    return max(ask(node * 2 + 1, l, mid, lf, rg),
               ask(node * 2 + 2, mid, r, lf, rg));
  }
  int ask(int l, int r) { ask(0, 0, B, l, r); }
};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  seg_tree st;
  st.init(N);
  int ans = 0;
  vector<int> dp(N, 0);
  for (int i = 1; i <= n; i++) {
    int x;
    cin >> x;
    int mx = max(st.ask(max(1, x - k), x + 1), st.ask(x, min(N, x + k + 1)));
    dp[i] = mx + 1;
    st.upd(x, dp[i]);
    ans = max(ans, dp[i]);
  }
  cout << ans << '\n';
  return 0;
}
