#include <bits/stdc++.h>
using namespace std;
long long int xo(long long int x, long long int y) {
  return (x | y) & (~x | ~y);
}
long long int bin_Expo(long long int x, long long int n) {
  if (x == 0) return 0;
  if (n == 0)
    return 1;
  else if (n % 2 == 0)
    return bin_Expo(x * x, n / 2);
  else
    return x * bin_Expo(x * x, (n - 1) / 2);
}
long long int mod_Expo(long long int x, long long int n, long long int M) {
  if (x == 0) return 0;
  if (n == 0)
    return 1;
  else if (n % 2 == 0)
    return mod_Expo((x * x) % M, n / 2, M);
  else
    return (x * mod_Expo((x * x) % M, (n - 1) / 2, M)) % M;
}
bool prime_check(long long int x) {
  bool prime = (x >= 2);
  for (long long int i = 2; i * i <= x; i++) {
    if (x % i == 0) {
      prime = false;
      break;
    }
  }
  return prime;
}
long long int logg(long long int base, long long int x) {
  return (long long int)(log(x) / log(base));
}
long long int a[300005], dp[300005], n, k;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int TESTS = 1;
  while (TESTS--) {
    long long int m, i, j, l, h, w, q, ans, x, y;
    cin >> n >> k;
    for (long long int i = 0; i < n; i++) cin >> a[i], dp[i] = 1;
    x = 1;
    for (long long int i = 1; i < n; i++) {
      for (long long int j = 0; j < i; j++) {
        if (abs(a[i] - a[j]) <= k) dp[i] = max(dp[i], dp[j] + 1);
      }
      x = max(x, dp[i]);
    }
    cout << x;
  }
  return 0;
}
