#include <bits/stdc++.h>
using namespace std;
const int N = 301234;
int a[N];
map<int, int> dp[N];
int n, k;
int ans(int in, int lst) {
  if (in < 0 || in >= n) return 0;
  if (dp[in][lst] != 0) {
    return dp[in][lst] - 1;
  }
  dp[in][lst] = max(ans(in + 1, lst), (abs(lst - a[in]) <= k || lst == -1) *
                                          (1 + ans(in + 1, a[in]))) +
                1;
  return dp[in][lst] - 1;
}
void solve() {
  cin >> n >> k;
  for (int i = 0; i < n; i++) cin >> a[i];
  cout << ans(0, -1);
}
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  solve();
}
