#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e18;
template <class T>
using pqueue = priority_queue<T, vector<T>, function<bool(T, T)>>;
template <class T>
inline void chmin(T& a, T b) {
  a = min(a, b);
}
template <class T>
inline void chmax(T& a, T b) {
  a = max(a, b);
}
void input();
void solve();
void daminput();
void naive();
void outputinput();
int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  input();
  solve();
  return 0;
}
int N, K;
vector<int> A;
void input() {
  cin >> N >> K;
  A.resize(N);
  for (int n = 0; n < N; n++) cin >> A[n];
}
void daminput() {}
template <class T>
class Segtree {
 private:
  vector<T> seg;
  long long RN;
  typedef function<T(T, T)> TT;
  TT f;
  T te;

 public:
  Segtree(long long N, TT _f, T e) : te(e) {
    RN = 1;
    while (RN < N) RN *= 2;
    seg.resize(2 * RN, te);
    f = _f;
  }
  Segtree(vector<T>& V, TT _f, T e) : te(e) {
    long long N = V.size();
    RN = 1;
    while (RN < N) RN *= 2;
    seg.resize(2 * RN, te);
    f = _f;
    for (long long n = 0; n < N; n++) seg[RN + n] = V[n];
    for (long long k = RN - 1; k >= 1; k--) {
      seg[k] = f(seg[2 * k], seg[2 * k + 1]);
    }
  }
  void set(long long n, T x) {
    seg[RN + n] = x;
    n = (RN + n) / 2;
    while (n >= 1) {
      seg[n] = f(seg[2 * n], seg[2 * n + 1]);
      n /= 2;
    }
  }
  void addl(long long n, T x) {
    seg[RN + n] = f(x, seg[RN + n]);
    n = (RN + n) / 2;
    while (n >= 1) {
      seg[n] = f(seg[2 * n], seg[2 * n + 1]);
      n /= 2;
    }
  }
  void addr(long long n, T x) {
    seg[RN + n] = f(seg[RN + n], x);
    n = (RN + n) / 2;
    while (n >= 1) {
      seg[n] = f(seg[2 * n], seg[2 * n + 1]);
      n /= 2;
    }
  }
  T get(long long l, long long r) {
    T ansl = te, ansr = te;
    r++;
    l += RN;
    r += RN;
    while (l < r) {
      if (l & 1) {
        ansl = f(ansl, seg[l]);
        l++;
      }
      if (r & 1) {
        r--;
        ansr = f(seg[r], ansr);
      }
      l >>= 1;
      r >>= 1;
    }
    return f(ansl, ansr);
  }
  T get(long long n) { return seg[RN + n]; }
  T operator[](long long n) { return seg[RN + n]; }
};
void solve() {
  vector<int> ord(N);
  for (int n = 0; n < N; n++) {
    ord[n] = n;
  }
  sort(ord.begin(), ord.end(), [&](int a, int b) {
    if (A[a] != A[b]) return A[a] < A[b];
    return a < b;
  });
  vector<int> change(N);
  for (int n = 0; n < N; n++) {
    change[ord[n]] = n;
  }
  Segtree<int> seg(
      N, [](int a, int b) { return max(a, b); }, 0);
  int ans = 0;
  for (int n = 0; n < N; n++) {
    int l, r;
    {
      int s = -1, e = N;
      while (e - s > 1) {
        int m = (e + s) / 2;
        if (A[ord[m]] < A[ord[n]] - K)
          s = m;
        else
          e = m;
      }
      l = e;
    }
    {
      int s = -1, e = N;
      while (e - s > 1) {
        int m = (e + s) / 2;
        if (A[ord[m]] <= A[ord[n]] + K)
          s = m;
        else
          e = m;
      }
      r = s;
    }
    int res = seg.get(l, r) + 1;
    chmax(ans, res);
    seg.set(ord[n], res);
  }
  cout << ans << "\n";
}
void naive() {}
void outputinput() {}
