#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("unroll-loops")
using namespace std;
const double pi = acos(-1);
bool isVowel(char ch) {
  if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u') {
    return 1;
  }
  return 0;
}
bool compare(pair<long long, long long> a, pair<long long, long long> b) {
  return a.second < b.second;
}
bool isPrime(long long n) {
  if (n % 2 == 0 && n != 2) {
    return false;
  }
  for (long long i = 3; i * i <= n; i += 2) {
    if (n % i == 0) {
      return false;
    }
  }
  return true;
}
long long binary_exp(long long x, long long n, long long mod) {
  if (n == 0) {
    return 1;
  } else if (n == 1) {
    return x % mod;
  } else {
    long long temp = binary_exp(x, n / 2, mod);
    temp = (temp * temp) % mod;
    if (n % 2 == 0) {
      return temp;
    } else {
      return ((x % mod) * temp) % mod;
    }
  }
}
map<long long, long long> m;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) {
    long long n, k, a, b, x, ans = INT_MIN, ma = INT_MIN;
    cin >> n >> k;
    long long arr[n];
    for (long long i = 0; i < n; i++) {
      cin >> arr[i];
    }
    long long dp[n];
    for (long long i = 0; i < n; i++) {
      dp[i] = 0;
    }
    long long ml[300001];
    for (long long i = 0; i <= 300000; i++) {
      ml[i] = 0;
    }
    for (long long i = 0; i < n; i++) {
      x = arr[i];
      a = max(0ll, x - k);
      b = min(300000ll, x + k);
      for (long long j = a; j <= b; j++) {
        dp[i] = max(dp[i], ml[j] + 1);
      }
      ml[x] = max(dp[i], ml[x]);
    }
    cout << *max_element(dp, dp + n) << endl;
  }
}
