#include <bits/stdc++.h>
using namespace std;
int INF = 1e9 + 7;
int mod = 998244353;
int main() {
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  for (int i = 0; i < N; i++) cin >> A[i];
  vector<int> DP(N);
  int ans = 0;
  for (int i = 0; i < N; i++) {
    DP[i]++;
    int count = 0;
    for (int j = 0; j < i; j++) {
      if (abs(A[j] - A[i]) <= K) count = max(count, DP[j]);
    }
    DP[i] += count;
    ans = max(ans, DP[i]);
  }
  cout << ans << endl;
}
