#include <bits/stdc++.h>
using namespace std;
int n, k, tot, maxx, a[300001], f[300001], tmp;
int dfs(int now) {
  if (f[now] != 0) return f[now] = max(f[now], tot);
  if (now == n) return f[now] = tot;
  for (int i = now + 1; i <= n; i++)
    if (fabs(a[now] - a[i]) <= k) {
      tmp = 0, tot++;
      tmp = max(dfs(i), tmp);
      tot--;
    }
  return f[now] = tmp;
}
int main() {
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    f[i] = 0;
  }
  for (int i = 1; i <= n; i++) tot = 1, maxx = max(maxx, dfs(i));
  cout << maxx << endl;
  return 0;
}
