#include <bits/stdc++.h>
using namespace std;
long long prime[1000001];
struct hash_pair {
  template <class T1, class T2>
  size_t operator()(const pair<T1, T2>& p) const {
    auto hash1 = hash<T1>{}(p.first);
    auto hash2 = hash<T2>{}(p.second);
    return hash1 ^ hash2;
  }
};
int temp[1000002] = {0};
void sieve() {
  for (int i = 1; i < 1000002; i++) temp[i] = 1;
  for (int i = 2; i < 1000002; i++) {
    temp[i]++;
    for (int j = i * 2; j < 1000002; j += i) {
      temp[j]++;
      ;
    }
  }
}
int k;
int rec(int a[], int i, int n, vector<int>& dp) {
  if (i >= n) return 0;
  if (dp[i] != -1) return dp[i];
  int c = 1;
  for (int j = i + 1; j < n; j++)
    if (abs(a[i] - a[j]) <= k)
      if (dp[j] == -1)
        c = max(c, 1 + rec(a, j, n, dp));
      else
        c = max(c, 1 + dp[j]);
  return dp[i] = c;
}
int main() {
  int n;
  cin >> n >> k;
  int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  vector<int> dp(n, -1);
  cout << rec(a, 0, n, dp);
  return 0;
}
