#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long long mx = 2e6 + 2;
const long long inf = 2e18;
const int sz = 256;
const int max_k = 20;
int n;
struct segmentree {
  vector<int> tree;
  segmentree() { tree.resize(mx, 0); }
  void update(int si, int ss, int se, int i, int val) {
    if (ss > i || se < i || ss > se) return;
    if (ss == se) {
      tree[si] = val;
      return;
    }
    int mid = (ss + se) >> 1;
    update(2 * si + 1, ss, mid, i, val);
    update(2 * si + 2, mid + 1, se, i, val);
    tree[si] = max(tree[2 * si + 1], tree[2 * si + 2]);
  }
  void update(int i, int diff) { update(0, 0, n - 1, i, diff); }
  int get_max(int si, int ss, int se, int qs, int qe) {
    if (ss > qe || ss > se || se < qs) return 0;
    if (ss >= qs && se <= qe) return tree[si];
    int mid = (ss + se) >> 1;
    return max(get_max(2 * si + 1, ss, mid, qs, qe),
               get_max(2 * si + 2, mid + 1, se, qs, qe));
  }
  int get_max(int l, int r) { return get_max(0, 0, n - 1, l, r); }
} st;
void input() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int k;
  cin >> n >> k;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) cin >> a[i];
  int ans = 0;
  vector<int> dp(n, 0);
  for (int i = 0; i < n; ++i) {
    int old = st.get_max(a[i], a[i]);
    int left = max(0, a[i] - k);
    int right = min(3000001, a[i] + k);
    int temp = st.get_max(left, right);
    dp[i] = max(dp[i], temp + 1);
    st.update(a[i], max(old, temp + 1));
  }
  cout << st.get_max(0, 300000) << "\n";
}
int main() {
  input();
  return 0;
}
