#include <bits/stdc++.h>
using namespace std;
vector<int> a;
int dp[300000] = {-1};
int n = 0, k = 0;
int tree(int f, int mae, int cnt) {
  int ans = cnt + 1;
  for (int i = f; i < (n); i++) {
    if (abs(mae - a[i]) <= k) {
      if (dp[i] != -1) {
        ans = max(ans, tree(i + 1, a[i], cnt + 1));
        dp[i] = ans;
      } else {
        ans = max(ans, dp[i]);
      }
    }
  }
  return ans;
}
int main() {
  int ans = 0, ave;
  cin >> n >> k;
  for (int i = 0; i < (n); i++) {
    int inter;
    cin >> inter;
    a.push_back(inter);
    ave += inter;
  }
  ave /= n;
  for (int i = 0; i < (n); i++) {
    ans = max(ans, tree(i + 1, a[i], 0));
  }
  cout << ans << endl;
  return 0;
}
