#include <bits/stdc++.h>
using namespace std;
vector<int> adj[100005];
int mark[100005] = {0};
void addedge(int u, int v) {
  adj[u].push_back(v);
  adj[v].push_back(u);
}
void dfs(int u) {
  mark[u] = 1;
  for (auto j : adj[u]) {
    if (!mark[j]) dfs(j);
  }
}
int main() {
  int n, k;
  cin >> n >> k;
  int arr[n];
  int LIS[n];
  int ans = 0;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    LIS[i] = 1;
  }
  for (int i = 1; i < n; i++) {
    for (int j = 0; j < i; j++) {
      if (abs(arr[i] - arr[j]) <= k) {
        LIS[i] = max(LIS[i], LIS[j] + 1);
        ans = max(ans, LIS[i]);
      }
    }
  }
  cout << ans;
}
