#include <bits/stdc++.h>
using namespace std;
template <typename... T>
void pp(T... args) {
  ((cout << args << " "), ...);
  cout << "\n";
}
template <typename... T>
void po(T... args) {
  ((cout << args << " "), ...);
  cout << "";
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int test = 1;
  for (int tt = 1; tt <= test; tt++) {
    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];
    }
    vector<int> dp(n, 0);
    long long int N = 3e5 + 5;
    int max_length[26] = {0};
    for (int i = 0; i < n; i++) {
      long long int curr = a[i];
      long long int lower = max(0LL, curr - k);
      long long int upper = min(N - 1, curr + k);
      for (long long int j = lower; j < upper + 1; j++) {
        dp[i] = max(dp[i], max_length[j] + 1);
      }
      max_length[curr] = max(dp[i], max_length[curr]);
    }
    long long int ans = 0;
    for (long long int i : dp) ans = max(i, ans);
    pp(ans);
  }
  return 0;
}
