#include <bits/stdc++.h>
using namespace std;
long long max(long long a, long long b) {
  if (a > b)
    return a;
  else
    return b;
}
long long min(long long a, long long b) {
  if (a < b)
    return a;
  else
    return b;
}
int tree[1300000];
int A[300005];
void update(int node, int b, int e, int i, int value) {
  if (i < b || i > e)
    return;
  else if (i == b && b == e) {
    tree[node] = value;
    return;
  }
  int left = node * 2;
  int right = left + 1;
  int mid = (b + e) / 2;
  if (i <= mid)
    update(left, b, mid, i, value);
  else
    update(right, mid + 1, e, i, value);
  tree[node] = max(tree[right], tree[left]);
}
int query(int node, int b, int e, int i, int j) {
  if (e < i || b > j)
    return 0;
  else if (b >= i && e <= j)
    return tree[node];
  int mid = (b + e) / 2;
  int left = node * 2;
  int right = left + 1;
  int P1 = query(left, b, mid, i, j);
  int P2 = query(right, mid + 1, e, i, j);
  return max(P1, P2);
}
int main() {
  int n, k;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) cin >> A[i];
  vector<int> v;
  int dp[300005] = {0};
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    int l = max(1, A[i] - k);
    int r = min(300000, A[i] + k);
    int x = query(1, 1, 300000, l, A[i]);
    int y = query(1, 1, 300000, A[i], r);
    dp[A[i]] = max(x, y) + 1;
    ans = max(ans, dp[A[i]]);
    update(1, 1, 300000, A[i], dp[A[i]]);
  }
  cout << ans << endl;
  return 0;
}
