#include <bits/stdc++.h>
using namespace std;
template <class U, class V>
ostream& operator<<(ostream& os, const pair<U, V>& p) {
  os << "(" << p.first << ", " << p.second << ")";
  return os;
}
template <class U, class V>
istream& operator>>(istream& in, pair<U, V>& p) {
  in >> p.first >> p.second;
  return in;
}
namespace cp {
template <typename T>
T min(T first) {
  return first;
}
template <typename T, typename... Args>
T min(T first, Args... args) {
  return std::min(first, min(args...));
}
template <typename T>
T max(T first) {
  return first;
}
template <typename T, typename... Args>
T max(T first, Args... args) {
  return std::max(first, max(args...));
}
};  // namespace cp
using cp::max;
using cp::min;
long long n;
const long long N = 2e6;
long long tree[N];
long long range_max(long long l, long long r) {
  long long res = 0;
  for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
    if (l & 1) {
      res = max(res, tree[l++]);
    }
    if (r & 1) {
      res = max(res, tree[--r]);
    }
  }
  return res;
}
void point_update(long long i, long long v) {
  for (tree[i += n] = v; i > 1; i >>= 1) {
    tree[i >> 1] = max(tree[i], tree[i ^ 1]);
  }
}
void solve() {
  long long nc;
  long long k;
  cin >> nc >> k;
  n = nc;
  long long arr[nc];
  for (long long i = 0; i < nc; i++) {
    cin >> arr[i];
  }
  point_update(arr[0], 1);
  long long re = 1;
  for (long long i = 1; i < nc; i++) {
    long long res = range_max(max(0ll, arr[i] - k), arr[i] + k + 1);
    point_update(arr[i], res + 1);
    re = max(re, res + 1);
  }
  cout << re << endl;
}
int main() {
  long long t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
