#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
constexpr ll LLINF{1001002003004005006};
constexpr int INTINF{1000000000};
template <typename T>
void maxs(T& x, T&& y) {
  x = std::max(x, y);
}
template <typename T>
void maxs(T& x, T& y) {
  x = std::max(x, y);
}
template <typename T>
void mins(T& x, T&& y) {
  x = std::min(x, y);
}
template <typename T>
void mins(T& x, T& y) {
  x = std::min(x, y);
}
int main() {
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (int i = 0; i < (n); ++i) cin >> a[i];
  map<int, int> mp;
  int max_ans{};
  for (int i = 0; i < (n); ++i) {
    int max_tmp{};
    for (int j = -k; j <= k; ++j) {
      int tmp = mp[a[i] + j];
      if (max_tmp < tmp) {
        max_tmp = mp[a[i] + j];
      }
    }
    maxs(mp[a[i]], max_tmp + 1);
    maxs(max_ans, max_tmp + 1);
  }
  cout << max_ans << '\n';
}
