#include <bits/stdc++.h>
using namespace std;
const long long mod = 998244353;
const int N = 300006;
const long long INF = 1e18;
struct seg_tree {
  int sz;
  vector<int> val;
  void init(int x) {
    sz = 1;
    while (sz < x) sz *= 2;
    val.resize(sz * 2);
  }
  int merge(int a, int b) { return max(a, b); }
  void build(int node, int l, int r, vector<int>& a) {
    if (r - l == 1) {
      if (l < a.size()) {
        val[node] = a[l];
      }
      return;
    }
    int mid = (l + r) / 2;
    build(node * 2 + 1, l, mid, a);
    build(node * 2 + 2, mid, r, a);
    val[node] = merge(val[node * 2 + 1], val[node * 2 + 2]);
  }
  void build(vector<int>& a) { build(0, 0, sz, a); }
  void upd(int node, int l, int r, int pos, long long x) {
    if (r - l == 1) {
      val[node] = x;
      return;
    }
    int mid = (l + r) / 2;
    if (mid > pos) upd(node * 2 + 1, l, mid, pos, x);
    if (mid <= pos) upd(node * 2 + 2, mid, r, pos, x);
    val[node] = merge(val[node * 2 + 1], val[node * 2 + 2]);
  }
  void upd(int pos, long long x) { upd(0, 0, sz, pos, x); }
  int ask(int node, int l, int r, int st, int dr) {
    if (dr <= l || st >= r) return 0;
    if (l >= st && r <= dr) return val[node];
    int mid = (l + r) / 2;
    return max(ask(node * 2 + 1, l, mid, st, dr),
               ask(node * 2 + 2, mid, r, st, dr));
  }
  int ask(int st, int dr) { return ask(0, 0, sz, st, dr); }
};
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;
}
