#include <bits/stdc++.h>
using namespace std;
void solve();
long long int mod(long long int x) {
  if (x < 0)
    return -1 * x;
  else
    return x;
}
bool needw(vector<int> v) {
  for (int i = 0; i < v.size() - 1; i++) {
    if (v[i + 1] > v[i]) return true;
  }
  return false;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t = 1;
  for (int i = 1; i <= t; i++) {
    solve();
    cout << "\n";
  }
  cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs"
       << "\n";
  return 0;
}
void solve() {
  int n, k;
  cin >> n >> k;
  int arr[n];
  int dp[n][n];
  memset(dp, 0, sizeof(dp));
  for (int i = 0; i < n; i++) dp[i][i] = 1;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  for (auto &i : arr) cerr << i << " ";
  cerr << "\n";
  for (int i = 0; i < n; i++) {
    int last = i;
    for (int j = i + 1; j < n; j++) {
      if (mod(arr[j] - arr[last]) <= k) {
        dp[i][j] = dp[i][last] + 1;
        last = j;
      } else
        dp[i][j] = dp[i][last];
      cerr << "l" << last;
    }
  }
  int max = -1;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      if (max < dp[i][j]) max = dp[i][j];
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      cerr << dp[i][j] << " ";
      if (max < dp[i][j]) max = dp[i][j];
    }
    cerr << "\n";
  }
  cout << max;
}
