#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using Vi = vector<int>;
int main() {
  int N, K;
  cin >> N >> K;
  vector<int> dp(300010, 0);
  int A;
  cin >> A;
  dp[A] = 1;
  for (int i = 2; i <= N; i++) {
    cin >> A;
    int max_dp = 0;
    for (int j = max(0, A - K); j <= min(300000, A + K); j++) {
      max_dp = max(max_dp, dp[j]);
    }
    dp[A] = max_dp + 1;
  }
  int ans = 0;
  for (int i = 1; i <= N; i++) {
    ans = max(ans, dp[i]);
  }
  cout << ans << endl;
}
