#include <bits/stdc++.h>
using namespace std;
int seg_tree[700000];
int dp[300001];
int find_max(int left, int right, int low, int high, int cur) {
  if (left == right) {
    return seg_tree[cur];
  }
  int mid = (left + right) / 2;
  if (low >= left && high <= mid) {
    return find_max(left, mid, low, high, cur * 2 + 1);
  } else if (low > mid && high <= right) {
    return find_max(mid + 1, right, low, high, cur * 2 + 2);
  } else {
    int low1 = max(left, low);
    int maxi1 = find_max(left, mid, low1, mid, cur * 2 + 1);
    int high1 = min(right, high);
    int maxi2 = find_max(mid + 1, right, mid + 1, high1, cur * 2 + 2);
    return max(maxi1, maxi2);
  }
}
void fix_it(int left, int right, int key, int ne, int cur) {
  if (left == right) {
    seg_tree[cur] = max(ne, seg_tree[cur]);
    return;
  }
  int mid = (left + right) / 2;
  if (key <= mid) {
    fix_it(left, mid, key, ne, cur * 2 + 1);
  } else {
    fix_it(mid + 1, right, key, ne, cur * 2 + 2);
  }
}
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> vec;
  for (int i = 0; i < n; i++) {
    int x;
    scanf("%d", &x);
    vec.push_back(x);
  }
  for (int i = n - 1; i >= 0; i--) {
    int low = max(1, vec[i] - k);
    int high = min(300000, vec[i] + k);
    int maxi = find_max(0, 300000, low, high, 0);
    dp[i] = 1 + maxi;
    fix_it(0, 300000, vec[i], dp[i], 0);
  }
  cout << dp[0] << endl;
  return 0;
}
