#include <bits/stdc++.h>
using namespace std;
int arr[300005];
int longest_subseq(int n, int k) {
  vector<int> dp(n, 0);
  int max_length[26] = {0};
  for (int i = 0; i < n; i++) {
    int curr = arr[i];
    int lower = max(0, curr - k);
    int upper = min(25, curr + k);
    for (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]);
  }
  int ans = 0;
  for (int i : dp) ans = max(i, ans);
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  int N, K;
  cin >> N >> K;
  for (int i = 0; i < N; i++) {
    cin >> arr[i];
  }
  cout << (longest_subseq(N, K));
  return 0;
}
