#include <bits/stdc++.h>
using namespace std;
const long long mxn = 5e5 + 5;
long long INF = 1000000000000000005LL;
void rishabh() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}
int n, k;
int dp[mxn][2], arr[mxn];
int call(int i, int val, int c) {
  if (i == n) return 0;
  if (dp[i][1] != -1 && dp[i][0] != -1) return max(dp[i][0], dp[i][1]);
  int &temp = dp[i][c];
  if (abs(arr[i] - val) <= k) {
    temp = max({call(i + 1, arr[i], 1) + 1, call(i + 1, val, 0),
                call(i + 1, val, 0) + 1});
  } else
    temp = call(i + 1, val, 0);
  return temp;
}
int main() {
  rishabh();
  memset(dp, -1, sizeof(dp));
  cin >> n >> k;
  for (int i = 0; i < n; i++) cin >> arr[i];
  cout << call(0, arr[0], 1);
}
