#include <bits/stdc++.h>
using namespace std;
const long long inf = 0x3f3f3f3f;
template <class T1, class T2, class T3>
void printTuple(tuple<T1, T2, T3> t) {
  cout << get<0>(t) << " " << get<1>(t) << " " << get<2>(t) << '\n';
}
template <class T1, class T2>
void printPair(pair<T1, T2> p) {
  cout << p.first << " " << p.second << '\n';
}
template <class T>
void printArray(vector<T> arr) {
  for (int i = 0; i < int((arr).size()); i++) {
    cout << arr[i] << " ";
  }
  cout << '\n';
}
struct segTree {
  int sz;
  long long baseValue = -1e9;
  vector<long long> tree;
  void init(long long n) {
    sz = 1;
    while (sz < n) sz *= 2;
    tree.assign(2 * sz, baseValue);
  }
  long long query(long long a, long long b) { return max(a, b); }
  void set(int idx, long long val) { set(idx, val, 0, 0, sz); }
  void set(int idx, long long val, int curr, int left, int right) {
    if (right - left == 1)
      tree[curr] = val;
    else {
      int mid = left + (right - left) / 2;
      if (idx < mid)
        set(idx, val, curr * 2 + 1, left, mid);
      else
        set(idx, val, curr * 2 + 2, mid, right);
      tree[curr] = query(tree[curr * 2 + 1], tree[curr * 2 + 2]);
    }
  }
  long long evaluate(int left, int right) {
    return evaluate(left, right, 0, 0, sz);
  }
  long long evaluate(int left, int right, int curr, int curr_left,
                     int curr_right) {
    if (curr_left >= right || left >= curr_right) return baseValue;
    if (curr_left >= left && curr_right <= right) return tree[curr];
    int mid = curr_left + (curr_right - curr_left) / 2;
    long long s1 = evaluate(left, right, curr * 2 + 1, curr_left, mid),
              s2 = evaluate(left, right, curr * 2 + 2, mid, curr_right);
    return query(s1, s2);
  }
};
int main() {
  std::ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, k, maxVal = -1;
  cin >> n >> k;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    maxVal = max(maxVal, a[i]);
  }
  segTree tree;
  tree.init(maxVal + 1);
  tree.set(a[0], 1);
  int ret = 1;
  for (int i = 1; i < n; i++) {
    int best = tree.evaluate(max(a[i] - k, 0), min(a[i] + k + 1, maxVal + 1));
    tree.set(a[i], best + 1);
    ret = max(ret, best + 1);
  }
  cout << ret << '\n';
}
