#include <bits/stdc++.h>
using namespace std;
long long dp[300010];
long long a[300010];
long long b[300010];
int main() {
  long long n, k;
  long long ans = 0;
  long long zero = 0;
  cin >> n >> k;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++) b[i] = 0;
  for (int i = 1; i < n; i++) {
    dp[i] = 1;
    for (int j = max(a[i] - k, zero); j <= a[i] + k; j++) {
      dp[i] = max(dp[i], b[j] + 1);
    }
    b[a[i]] = max(dp[i], b[a[i]]);
    ans = max(ans, dp[i]);
  }
  cout << ans << endl;
}
