#include <bits/stdc++.h>
using namespace std;
int dp[300001];
int main() {
  int n, k;
  cin >> n >> k;
  int arr[n];
  for (int i = 0; i < n; i++) cin >> arr[i];
  dp[arr[0]] = 1;
  int m = 0;
  for (int i = 1; i < n; i++) {
    int c = 0;
    for (int s = max(0, arr[i] - k); s <= min(arr[i] + k, 300000); s++) {
      if (dp[s] + 1 > c) c = dp[s] + 1;
    }
    dp[arr[i]] = c;
    if (dp[arr[i]] > m) m = dp[arr[i]];
  }
  cout << m << endl;
}
