#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> counter(N + 1, 0);
  vector<int> ans(N + 1, 0);
  vector<int> prev(N, 0);
  for (int i = N - 1; i >= 0; i--) {
    counter[A[i]]++;
    int max_v = 0;
    for (int j = -K; j <= K; j++) {
      if (A[i] + j < 0) continue;
      max_v = max(max_v, ans[A[i] + j] + 1);
    }
    ans[A[i]] = max_v;
  }
  int max_ans = 0;
  for (int i = 0; i < (N); i++) max_ans = max(max_ans, ans[i]);
  cout << max_ans << endl;
}
