#include <bits/stdc++.h>
using namespace std;
const int d4i[4] = {-1, 0, 1, 0}, d4j[4] = {0, 1, 0, -1};
const int d8i[8] = {-1, -1, 0, 1, 1, 1, 0, -1},
          d8j[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const long long inf = 1e9;
const int mxN = 2e6 + 1;
const int mod = 1e9 + 7;
int vis[mxN] = {};
vector<int> v[mxN];
int dp[mxN] = {};
void solvesolve(int start) {
  vis[start] = 1;
  for (auto x : v[start]) {
    if (dp[x] <= 1 + dp[start]) {
      vis[x] = 1;
      dp[x] = 1 + dp[start];
      solvesolve(x);
    }
  }
}
void solve() {
  int n, k;
  cin >> n >> k;
  int arr[n];
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      if (abs(arr[i] - arr[j]) <= k && abs(arr[i] - arr[j]) >= 0)
        v[i].push_back(j);
    }
  }
  int ans = -1;
  for (int i = 0; i < n; i++) {
    if (!vis[i]) {
      solvesolve(i);
      dp[i] = 0;
    }
  }
  for (int i = 0; i < n; i++) {
    ans = max(ans, dp[i]);
  }
  cout << ans + 1 << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
