#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18;
const long long mod = 1e9 + 7;
void inputoutput() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
}
vector<int> adj[100500];
vector<bool> vis(100500);
vector<int> d(100500);
queue<int> q;
void bfs(int v) {
  q.push(v);
  vis[v] = true;
  while (!q.empty()) {
    int x = q.front();
    q.pop();
    for (auto u : adj[x]) {
      if (!vis[u]) {
        vis[u] = true;
        q.push(u);
        d[u] = d[v] + 1;
      }
    }
  }
}
void dfs(int v) {
  vis[v] = true;
  for (auto u : adj[v]) {
    if (!vis[u]) dfs(u);
  }
}
void solve() {
  long long int n, k;
  cin >> n >> k;
  vector<long long int> ar(n);
  for (long long int i = 0; i < n; ++i) cin >> ar[i];
  long long int llis[n];
  memset(llis, 1, sizeof(llis));
  for (long long int i = 0; i < n; ++i) {
    long long int len = 1;
    for (long long int j = i - 1; j >= 0; --j) {
      if (abs(ar[i] - ar[j]) <= k) {
        len = max(len, 1 + llis[j]);
      }
    }
    llis[i] = len;
  }
  long long int ans = INT_MIN;
  for (long long int i = 0; i < n; ++i) {
    ans = max(ans, llis[i]);
  }
  cout << ans << "\n";
}
int main() {
  inputoutput();
  solve();
  return 0;
}
