#include <bits/stdc++.h>
using namespace std;
template <class c>
struct rge {
  c b, e;
};
template <class c>
rge<c> range(c i, c j) {
  return rge<c>{i, j};
}
template <class c>
auto dud(c* x) -> decltype(cerr << *x, 0);
template <class c>
char dud(...);
struct debug {
  template <class c>
  debug& operator<<(const c&) {
    return *this;
  }
};
struct node {
  int low, high;
  int mx;
  node *l, *r;
  node(int _low, int _high, int A[] = NULL)
      : low(_low), high(_high), mx(0), l(NULL), r(NULL) {
    if (A == NULL) return;
    if (low == high) {
      mx = A[low];
    } else {
      l = new node(low, (low + high) / 2, A),
      r = new node((low + high + 2) / 2, high, A);
      combine();
    }
  }
  void combine() {
    if (l == NULL) {
      return;
    }
    mx = max(l->mx, r->mx);
  }
  void point_update(int pos, int val) {
    if (low == high) {
      mx = val;
    } else {
      int mid = (low + high) / 2;
      if (pos <= mid) {
        l->point_update(pos, val);
      } else {
        r->point_update(pos, val);
      }
      combine();
    }
  }
  int range_max(int lt, int rt) {
    if (lt == low && rt == high) {
      return mx;
    }
    if (l == NULL) {
      return mx;
    }
    int mid = (low + high) / 2;
    if (rt <= mid) {
      return l->range_max(lt, rt);
    }
    if (lt > mid) return r->range_max(lt, rt);
    return max(l->range_max(lt, mid), r->range_max(mid + 1, rt));
  }
  ~node() {
    if (l != NULL) delete (l);
    if (r != NULL) delete (r);
  }
};
int n, k;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> k;
  vector<int> a(n);
  int grosso = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    grosso = max(grosso, a[i]);
  }
  grosso += k;
  int dp[grosso + 1];
  memset(dp, 0, sizeof(dp));
  node tree(0, grosso, dp);
  for (int i = 0; i < n; i++) {
    int meglio = 0;
    if (a[i] - k >= 0 && a[i] + k <= grosso) {
      meglio = max(meglio, tree.range_max(a[i] - k, a[i]));
      meglio = max(meglio, tree.range_max(a[i], a[i] + k));
    } else if (a[i] + k <= grosso) {
      meglio = max(meglio, tree.range_max(a[i], a[i] + k));
    } else if (a[i] - k >= 0) {
      meglio = max(meglio, tree.range_max(a[i] - k, a[i]));
    }
    dp[a[i]] = max(dp[a[i]], meglio + 1);
    tree.point_update(a[i], dp[a[i]]);
  }
  int ans = 0;
  for (int i = 0; i <= grosso; i++) {
    ans = max(ans, dp[i]);
  }
  cout << ans << endl;
}
