#include <bits/stdc++.h>
const int N = 1e5 + 5;
const long double pi = 3.141592653;
const long long MOD = 1e9 + 7;
const long long mod = 998244353;
const long long INF = 9223372036854775807LL;
using namespace std;
int dx[9] = {1, -1, 0, 0, 1, 1, -1, -1, 0};
int dy[9] = {0, 0, 1, -1, 1, -1, 1, -1, 0};
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int T = 1;
  while (T--) {
    int n, i, j, k, ans = 0;
    cin >> n >> k;
    vector<int> a(n + 1), dp(n + 5, 0);
    for (i = 1; i <= n; i++) cin >> a[i];
    dp[1] = 1;
    for (i = 2; i <= n; i++) {
      for (j = 1; j < i; j++) {
        if (abs(a[i] - a[j]) <= k) dp[i] = max(dp[i], dp[j] + 1);
      }
      dp[i] = max(dp[i], 1);
    }
    for (i = 1; i <= n; i++) ans = max(ans, dp[i]);
    cout << ans;
  }
  return 0;
}
