#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 10;
int a[N], dp[N];
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j < i; j++)
      if (abs(a[i] - a[j]) <= k) dp[i] = max(dp[i], dp[i] + 1);
  int ans = -0x3f3f3f;
  for (int i = 1; i <= n; i++) ans = max(ans, dp[i]);
  printf("%d\n", ans);
  return 0;
}
