#include <bits/stdc++.h>
using namespace std;
map<int, int> mp;
int find(int low, int high) {
  if (high < low) return 0;
  if (high == low) return mp[low];
  int mid = low + (high - low) / 2;
  return max(find(low, mid), find(mid + 1, high));
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, k;
  cin >> n >> k;
  vector<int> ques(n);
  int ma = 0;
  for (int i = 0; i < n; i++) {
    cin >> ques[i];
    ma = max(ma, ques[i]);
  }
  int ans = 1;
  for (int i = 0; i < n; i++) {
    int low = max(0, ques[i] - k);
    int high = min(ma, ques[i] + k);
    int l = find(low, high);
    mp[ques[i]] = l + 1;
    ans = max(ans, l + 1);
  }
  cout << ans << "\n";
  return 0;
}
