#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const long long INF = 1LL << 60;
const int IINF = 1000000000;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  for (int i = 0; i < (N); i++) cin >> A[i];
  vector<int> ans(300000 + 1, 0);
  for (int i = N - 1; i >= 0; i--) {
    int max_v = 0;
    for (int j = max(0, A[i] - K); j <= min(A[i] + K, 300000); j++) {
      max_v = max(max_v, ans[j] + 1);
    }
    ans[A[i]] = max_v;
  }
  int max_ans = 0;
  for (int i = 0; i < (300000 + 1); i++) max_ans = max(max_ans, ans[i]);
  cout << max_ans << endl;
}
