#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) {
      ans = max(ans, dp[i] + 1);
    }
  }
  return ans;
}
int main() {
  int ans = 0;
  cin >> n >> k;
  for (int i = 0; i < (n); i++) {
    int inter;
    cin >> inter;
    a.push_back(inter);
    dp[i] = -1;
  }
  for (int j = 0; j < (n); j++) {
    int i = n - j - 1;
    int cnt = tree(i + 1, a[i], 0);
    dp[i] = cnt;
    ans = max(ans, cnt);
  }
  cout << ans << endl;
  return 0;
}
