#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
const long long N = 3e5 + 5;
const long long INF = 1e18L;
vector<string> split(const string& s, char c) {
  vector<string> v;
  stringstream ss(s);
  string x;
  while (getline(ss, x, c)) v.emplace_back(x);
  return move(v);
}
template <typename T, typename... Args>
inline string arrStr(T arr, long long n) {
  stringstream s;
  s << "[";
  for (long long i = 0; i < n - 1; i++) s << arr[i] << ",";
  if (n > 0) s << arr[n - 1];
  s << "]";
  return s.str();
}
inline void __trace_begin(long long line) { cerr << "#" << line << ": "; }
template <typename T>
inline void __trace_out_var(vector<T> val) {
  cerr << arrStr(val, val.size());
}
template <typename T>
inline void __trace_out_var(T* val) {
  cerr << arrStr(val, 10);
}
template <typename T>
inline void __trace_out_var(T val) {
  cerr << val;
}
inline void __trace(vector<string>::iterator it) { cerr << '\n'; }
template <typename T, typename... Args>
inline void __trace(vector<string>::iterator it, T a, Args... args) {
  cerr << it->substr((*it)[0] == ' ', it->length()) << "=";
  __trace_out_var(a);
  cerr << "; ";
  __trace(++it, args...);
}
long long ar[N];
long long dp[N];
long long tree[2 * N];
void update(long long pos, long long v, long long l, long long r,
            long long tn) {
  if (l == r && l == pos) {
    tree[tn] = v;
    return;
  }
  long long mid = (l + r) / 2;
  if (pos >= l && pos <= mid)
    update(pos, v, l, mid, tn * 2 + 1);
  else if (pos > mid && pos <= r)
    update(pos, v, mid + 1, r, 2 * tn + 2);
  tree[tn] = max(tree[tn * 2 + 1], tree[tn * 2 + 2]);
}
long long qry(long long l, long long r, long long ql, long long qr,
              long long tn) {
  if (l > qr || r < ql) return -1;
  if (l >= ql && r <= qr) return tree[tn];
  long long mid = (l + r) / 2;
  return max(qry(l, mid, ql, qr, tn * 2 + 1),
             qry(mid + 1, r, ql, qr, 2 * tn + 2));
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  long long T = 1;
  while (T--) {
    long long n;
    cin >> n;
    long long k;
    cin >> k;
    long long ans = 0;
    for (long long i = 0; i < n; i++) {
      cin >> ar[i];
      long long l = max(0ll, ar[i] - k);
      long long r = ar[i] + k;
      long long x = qry(l, r, 1, N, 0);
      ans = max(ans, x);
      update(ar[i], x + 1, 1, N, 0);
    }
    cout << ans << '\n';
  }
  return 0;
}
