#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
template <typename T>
bool mmax(T &m, const T q) {
  if (m < q) {
    m = q;
    return true;
  } else
    return false;
}
template <typename T>
bool mmin(T &m, const T q) {
  if (m > q) {
    m = q;
    return true;
  } else
    return false;
}
void __print(long long first) { cerr << first; }
void __print(long first) { cerr << first; }
void __print(unsigned first) { cerr << first; }
void __print(unsigned long first) { cerr << first; }
void __print(unsigned long long first) { cerr << first; }
void __print(float first) { cerr << first; }
void __print(double first) { cerr << first; }
void __print(long double first) { cerr << first; }
void __print(char first) { cerr << '\'' << first << '\''; }
void __print(const char *first) { cerr << '\"' << first << '\"'; }
void __print(const string &first) { cerr << '\"' << first << '\"'; }
void __print(bool first) { cerr << (first ? "true" : "false"); }
template <typename T, typename V>
void __print(const pair<T, V> &first) {
  cerr << '{';
  __print(first.first);
  cerr << ',';
  __print(first.second);
  cerr << '}';
}
template <typename T>
void __print(const T &first) {
  long long f = 0;
  cerr << '{';
  for (auto &i : first) cerr << (f++ ? "," : ""), __print(i);
  cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) {
  __print(t);
  if (sizeof...(v)) cerr << ", ";
  _print(v...);
}
mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
const long long maxn = (1 << 19);
long long tree[4 * maxn];
void upd(long long k, long long v) {
  k += maxn;
  tree[k] = max(tree[k], v);
  for (long long i = k / 2; i != 0; i /= 2)
    tree[i] = max(tree[i * 2], tree[i * 2 + 1]);
}
long long qry(long long l, long long r) {
  l += maxn;
  r += maxn;
  long long res = 0;
  while (l <= r) {
    if (l % 2 == 1) res = max(res, tree[l++]);
    if (r % 2 == 0) res = max(res, tree[r--]);
    l /= 2;
    r /= 2;
  }
  return res;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(12);
  long long n, k;
  cin >> n >> k;
  long long ans = 1;
  for (long long i = 0; i < n; i++) {
    long long first;
    cin >> first;
    long long l = max(0ll, first - k);
    long long r = first + k;
    long long t = qry(l, r);
    ans = max(ans, t + 1);
    upd(first, t + 1);
  }
  cout << ans;
  return 0;
}
