#include <bits/stdc++.h>
using namespace std;
long long int pow_mod(long long int a, long long int b) {
  long long int res = 1;
  while (b != 0) {
    if (b & 1) {
      res = (res * a) % 1000000007;
    }
    a = (a * a) % 1000000007;
    b /= 2;
  }
  return res;
}
long long int st[4 * 30000 + 2];
void solve() {
  long long int n, k;
  cin >> n >> k;
  long long int a[n];
  for (long long int i = 0; i < n; i++) cin >> a[i];
  function<void(long long int, long long int, long long int, long long int,
                long long int)>
      update = [&](long long int second, long long int se, long long int si,
                   long long int id, long long int val) {
        if (second == se && second == id) {
          st[si] = val;
          return;
        }
        if (id > se || id < second) return;
        long long int mid = (second + se) / 2;
        update(second, mid, 2 * si + 1, id, val);
        update(mid + 1, se, 2 * si + 2, id, val);
        st[si] = max(st[2 * si + 1], st[2 * si + 2]);
      };
  function<long long int(long long int, long long int, long long int,
                         long long int, long long int)>
      get_min = [&](long long int second, long long int se, long long int si,
                    long long int l, long long int r) {
        if (l > r) return 0LL;
        if (r < second || se < l) return 0LL;
        if (second >= l && se <= r) return st[si];
        long long int mid = (second + se) / 2;
        return max(get_min(second, mid, 2 * si + 1, l, r),
                   get_min(mid + 1, se, 2 * si + 2, l, r));
      };
  long long int dp[30000 + 1];
  for (long long int i = 0; i < 30000 + 1; i++) {
    update(0LL, 30000LL, 0LL, i, 0LL);
    dp[i] = 0;
  }
  long long int ans = 0LL;
  for (long long int i = 0; i < n; i++) {
    long long int l = max(0LL, a[i] - k);
    long long int r = min(30000LL, a[i] + k);
    long long int res = get_min(0LL, 30000LL, 0LL, l, r);
    update(0LL, 30000LL, 0LL, a[i], 1LL);
    dp[a[i]] = max(dp[a[i]], 1 + res);
    update(0LL, 30000LL, 0LL, a[i], dp[a[i]]);
  }
  for (long long int i = 0; i < n; i++) ans = max(ans, dp[a[i]]);
  cout << ans << endl;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int t;
  t = 1;
  while (t--) solve();
  return 0;
}
