#include <bits/stdc++.h>
using namespace std;
int longestSubseqWithDiffOne(long long int arr[], long long int n,
                             long long int k) {
  long long int dp[n];
  for (long long int i = 0; i < n; i++) dp[i] = 1;
  for (long long int i = 1; i < n; i++) {
    for (long long int j = 0; j < i; j++)
      if (abs(arr[i] - arr[j]) <= k) dp[i] = max(dp[i], dp[j] + 1);
  }
  long long int result = 1;
  for (long long int i = 0; i < n; i++)
    if (result < dp[i]) result = dp[i];
  return result;
}
int main() {
  long long int n, k;
  cin >> n >> k;
  long long int arr[n];
  for (long long int i = 0; i < n; ++i) cin >> arr[i];
  cout << longestSubseqWithDiffOne(arr, n, k);
  return 0;
}
