#include <bits/stdc++.h>
using namespace std;
int tree[1000000];
void updatetree(int ind, int l, int h, int i, int val) {
  if (i < l || i > h || l > h) return;
  if (l == h) {
    tree[ind] = val;
    return;
  }
  int md = l + (h - l) / 2;
  updatetree(2 * ind + 1, l, md, i, val);
  updatetree(2 * ind + 2, md + 1, h, i, val);
  tree[ind] = max(tree[2 * ind + 1], tree[2 * ind + 2]);
}
int query(int ind, int l, int r, int i, int j) {
  if (l > r || l > j || r < i) return 0;
  if (i <= l && j >= r) {
    return tree[ind];
  }
  int md = l + (r - l) / 2;
  int l1 = query(2 * ind + 1, l, md, i, j);
  int r1 = query(2 * ind + 2, md + 1, r, i, j);
  return max(l1, r1);
}
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> v(n);
  for (int i = 0; i < n; i++) cin >> v[i];
  int dp[n][2];
  updatetree(0, 0, 300000, v[0], 1);
  dp[0][0] = 1;
  dp[0][1] = 1;
  int ans = 1;
  map<int, int> m;
  m[v[0]]++;
  for (int i = 1; i < n; i++) {
    int x = query(0, 0, 300000, v[i] - k, v[i]);
    dp[i][0] = x + 1;
    int y = query(0, 0, 300000, v[i], v[i] + k);
    dp[i][1] = y + 1;
    ans = max(ans, max(dp[i][0], dp[i][1]));
    m[v[i]]++;
    updatetree(0, 0, 300000, v[i], max(tree[v[i]], max(dp[i][0], dp[i][1])));
  }
  cout << ans;
  return 0;
}
