#include <bits/stdc++.h>
using namespace std;
void sep() { cout << "-------------BLOCK-----------------\n"; }
template <typename T>
void debugv(vector<T> arr) {
  for (auto t : arr) cout << t << " ";
  cout << "\n";
}
template <typename T>
void debugarr(T arr, int n) {
  for (int i = 0; i < n; i++) cout << arr[i] << " ";
  cout << "\n";
}
long long __min(long long a, long long b) { return a < b ? a : b; }
long long __max(long long a, long long b) { return a > b ? a : b; }
const int maxn = 3e5 + 1;
long long arr[maxn], n, m, t, k, q;
unordered_map<long long, long long> u;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> k;
  for (int i = 0; i < n; i++) cin >> arr[i];
  vector<long long> dp(n, 1);
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < i; j++) {
      if (abs(arr[i] - arr[j]) <= k && dp[i] < 1 + dp[j]) dp[i] = 1 + dp[j];
    }
    ans = __max(ans, dp[i]);
  }
  if (ans == 1) ans = 0;
  cout << ans << endl;
}
