#include <bits/stdc++.h>
using namespace std;
set<int> S;
int A[100005], B[100005];
int tree[400005];
int get_max(int left, int right, int L, int R, int root) {
  if (left > right || left > R || right < L) return 0;
  if (left >= L && right <= R) return tree[root];
  int mid = (left + right) / 2;
  return max(get_max(left, mid, L, R, root * 2),
             get_max(mid + 1, right, L, R, root * 2 + 1));
}
void update(int left, int right, int x, int val, int root) {
  if (left > right || left > x || right < x) return;
  if (left == right && right == x) {
    tree[root] = val;
    return;
  }
  int mid = (left + right) / 2;
  update(left, mid, x, val, root * 2);
  update(mid + 1, right, x, val, root * 2 + 1);
  tree[root] = max(tree[root * 2], tree[root * 2 + 1]);
}
int main() {
  int N, K;
  cin >> N >> K;
  for (int i = 1; i <= N; i++) {
    cin >> A[i];
    S.insert(A[i]);
  }
  int k = 1;
  for (set<int>::iterator it = S.begin(); it != S.end(); it++) B[k++] = *it;
  k--;
  int ans = 0;
  for (int i = 1; i <= N; i++) {
    int x = lower_bound(B + 1, B + 1 + k, A[i]) - B;
    int y = lower_bound(B + 1, B + 1 + k, A[i] - K) - B;
    int z = upper_bound(B + 1, B + 1 + k, A[i] + K) - B - 1;
    int new_ans = get_max(1, N, y, z, 1) + 1;
    ans = max(ans, new_ans);
    update(1, N, x, new_ans, 1);
  }
  cout << ans << endl;
  return 0;
}
