#include <bits/stdc++.h>
using namespace std;
int arr[300003], tree[1025 * 1025], dp[300003];
void update(int first, int a, int b, int v, int r) {
  if (first < a or first > b) return;
  if (first == a and a == b) {
    tree[r] = v;
    return;
  }
  int md = (a + b) / 2;
  update(first, a, md, v, 2 * r);
  update(first, md + 1, b, v, 2 * r + 1);
  tree[r] = max(tree[2 * r], tree[2 * r + 1]);
}
int query(int first, int second, int a, int b, int r) {
  if (a >= first and b <= second) return tree[r];
  if (second < a or first > b) return 0;
  int md = (a + b) / 2;
  return max(query(first, second, a, md, 2 * r),
             query(first, second, md + 1, b, 2 * r + 1));
}
int main() {
  int n, k;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &arr[i]);
  }
  for (int i = 1; i <= n; i++) {
    int i1 = query(max(arr[i] - k, 0), arr[i], 1, 300000, 1);
    int i2 = query(arr[i], min(300000, arr[i] + k), 1, 300000, 1);
    dp[i] = max(dp[i1], dp[i2]) + 1;
    update(arr[i], 1, 300000, i, 1);
  }
  int mx = 0;
  for (int i = 1; i <= n; i++) {
    mx = max(mx, dp[i]);
  }
  cout << mx;
  return 0;
}
