#include <bits/stdc++.h>
using namespace std;
int arr[1000000];
int longest_subseq(int n, int k) {
  int i;
  vector<int> dp;
  int max_length[1000000];
  for (i = 0; i < n; i++) {
    max_length[i] = 0;
    dp.push_back(0);
  }
  for (i = 0; i < n; i++) {
    int curr = arr[i];
    int lower = max(0, curr - k);
    int upper = 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 (i = 0; i < n; i++) {
    ans = max(dp[i], ans);
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int i, j, k, x, y, z, n;
  cin >> n >> k;
  for (i = 0; i < n; i++) {
    cin >> arr[i];
  }
  y = longest_subseq(n, k);
  cout << y << endl;
}
