#include <bits/stdc++.h>
using namespace std;
int dp[300001];
set<int> s;
int main() {
  int n, k;
  cin >> n >> k;
  int arr[n];
  for (int i = 0; i < n; i++) cin >> arr[i];
  dp[arr[0]] = 1;
  s.insert(arr[0]);
  int m = 0;
  for (int i = 1; i < n; i++) {
    set<int>::iterator it1 = s.lower_bound(arr[i] - k);
    set<int>::iterator it2 = s.upper_bound(arr[i] + k);
    int c = 1;
    if (it1 != s.end() && it2 != s.begin()) {
      while (it1 != it2) {
        int temp = *it1;
        if (dp[temp] + 1 > c) c = dp[temp] + 1;
        ++it1;
      }
    }
    dp[arr[i]] = c;
    if (c > m) m = c;
    s.insert(arr[i]);
  }
  cout << m << endl;
}
