#include <bits/stdc++.h>
using namespace std;
int k;
int cost(int x, int y) {
  if (abs(x - y) <= k)
    return 1;
  else
    return 0;
}
void solve() {
  int n;
  cin >> n >> k;
  vector<int> a(n);
  for (int i = 0; i < int(n); i++) cin >> a[i];
  vector<int> dp(n + 1);
  dp[0] = 1;
  for (int i = 1; i < n; i++) {
    for (int j = i - 1; j >= 0; j--) {
      dp[i] = max(dp[i], dp[j] + cost(a[i], a[j]));
    }
  }
  cout << *max_element(dp.begin(), dp.end()) << endl;
}
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  solve();
  return 0;
}
