#include <bits/stdc++.h>
using namespace std;
int N, K;
int A[300003], best[300003];
int T[300003 * 3];
inline int min(int a, int b) { return a < b ? a : b; }
inline int max(int a, int b) { return a > b ? a : b; }
void update(int node, int st, int dr, int pos, int val) {
  if (st == dr) {
    T[node] = val;
    return;
  }
  int m = (st + dr) >> 1;
  if (m > pos) {
    update(node << 1, st, m, pos, val);
  } else {
    update((node << 1) + 1, m + 1, dr, pos, val);
  }
  T[node] = max(T[node << 1], T[(node << 1) + 1]);
}
int query(int node, int st, int dr, int l, int r) {
  if (l <= st && r >= dr) {
    return T[node];
  }
  int m = (st + dr) >> 1;
  int v1 = 0, v2 = 0;
  if (m >= l) {
    v1 = query(node << 1, st, m, l, r);
  }
  if (m < r) {
    v2 = query((node << 1) + 1, m + 1, dr, l, r);
  }
  return max(v1, v2);
}
int main() {
  int best = 0;
  cin >> N >> K;
  for (int i = 0; i < N; ++i) {
    cin >> A[i];
  }
  for (int i = 0; i < N; ++i) {
    int res = query(1, 0, 300003, max(A[i] - K, 0), min(A[i] + K, 300003)) + 1;
    update(1, 0, 300003, A[i], res);
    if (res > best) {
      best = res;
    }
  }
  cout << best;
  return 0;
}
