#include <bits/stdc++.h>
using namespace std;
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  os << '{';
  string sep;
  for (const auto &x : v) os << sep << x, sep = ", ";
  return os << '}';
}
template <typename T, size_t size>
ostream &operator<<(ostream &os, const array<T, size> &arr) {
  os << '{';
  string sep;
  for (const auto &x : arr) os << sep << x, sep = ", ";
  return os << '}';
}
template <typename A, typename B>
ostream &operator<<(ostream &os, const pair<A, B> &p) {
  return os << '(' << p.first << ", " << p.second << ')';
}
void dbg_out() { cerr << '\n'; }
template <typename Head, typename... Tail>
void dbg_out(Head H, Tail... T) {
  cerr << ' ' << H;
  dbg_out(T...);
}
const long long N = 1e5 + 5, mod = 1e9 + 7, bit = 61;
template <typename T>
class segment {
 public:
  vector<T> st;
  long long long long n;
  segment() {}
  segment(long long long long _n) {
    n = _n;
    st.resize(2 * n);
  }
  T merge(T a, T b) { return max(a, b); }
  void create() {
    for (long long long long i = n - 1; i > 0; i--) {
      st[i] = merge(st[i << 1], st[(i << 1) | 1]);
    }
  }
  void update(long long long long idx, T val) {
    for (st[idx += n - 1] = val; idx > 1; idx >>= 1) {
      st[idx >> 1] = merge(st[min(idx, idx ^ 1)], st[max(idx, idx ^ 1)]);
    }
  }
  T query(long long long long l, long long long long r) {
    T ans{};
    T ansl{};
    T ansr{};
    for (l += n - 1, r += n - 1; l < r; l >>= 1, r >>= 1) {
      if (l & 1) {
        ansl = merge(ansl, st[l++]);
      }
      if (r & 1) {
        ansr = merge(st[--r], ansr);
      }
    }
    ans = merge(ansl, ansr);
    return ans;
  }
};
signed main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  long long t = 1;
  for (long long tc = 1; tc <= t; tc++) {
    long long n, k;
    cin >> n >> k;
    long long a[n];
    for (long long i = 0; i <= n - 1; i++) {
      cin >> a[i];
    }
    segment<long long> obj(300000);
    obj.create();
    long long ans = 0;
    for (long long i = 0; i <= n - 1; i++) {
      long long l = max(0ll, a[i] - k);
      long long r = min(300000ll, a[i] + k);
      long long curr = 1 + obj.query(l, r + 1);
      ans = max(ans, curr);
      obj.update(a[i], max(curr, obj.st[a[i] + 300000 - 1]));
    }
    cout << ans << '\n';
  }
  return 0;
}
