#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int n, difference;
  cin >> n >> difference;
  vector<int> arr(n);
  for (int i = 0; i < n; ++i) cin >> arr[i];
  int maxL = 1;
  int maxVal = *max_element(arr.begin(), arr.end());
  int minVal = *min_element(arr.begin(), arr.end());
  int range = maxVal - minVal + 1;
  vector<int> max_length(range, 0), dp(n, 0);
  for (int i = 0; i < n; ++i) {
    int lower = max(minVal, arr[i] - difference);
    int upper = min(maxVal, arr[i] + difference);
    for (int j = lower; j < upper + 1; ++j) {
      dp[i] = max(dp[i], max_length[j] + 1);
    }
    max_length[arr[i]] = max(dp[i], max_length[arr[i]]);
  }
  int ans = 0;
  for (int i : dp) ans = max(i, ans);
  cout << ans;
  return 0;
}
