#include <bits/stdc++.h>
using namespace std;
const int N = int(1e6) + 1;
priority_queue<pair<long long, pair<long long, long long>>> pq;
int st[2 * N + 1] = {0};
int n;
void build() {
  for (int i = n - 1; i > 0; i--) st[i] = max(st[i << 1], st[i << 1 | 1]);
}
void update(int pos, int val) {
  st[pos + n] = val;
  for (int i = pos + n; i > 1; i >>= 1) {
    st[i >> 1] = max(st[i], st[i ^ 1]);
  }
}
void modify(int pos, int val) {
  st[pos + n] = val;
  for (int i = pos + n; i > 1; i >>= 1) {
    st[i >> 1] = st[i] + st[i ^ 1];
  }
}
int maxquery(int l, int r) {
  int res = 0;
  l += n;
  r += n;
  while (l < r) {
    if (l & 1) {
      res = max(st[l], res);
      l++;
    }
    if (r & 1) {
      r--;
      res = max(st[r], res);
    }
    l >>= 1;
    r >>= 1;
  }
  return res;
}
int queury(int l, int r) {
  int res = 0;
  l += n;
  r += n;
  while (l < r) {
    if (l & 1) {
      res += st[l];
      l++;
    }
    if (r & 1) {
      r--;
      res += st[r];
    }
    l >>= 1;
    r >>= 1;
  }
  return res;
}
int main() {
  int k;
  cin >> n >> k;
  vector<int> v(n);
  for (int i = 0; i < n; i++) cin >> v[i];
  build();
  int maxm, l, r;
  vector<int> dp(n, 1);
  for (int i = 0; i < n; i++) {
    l = max(0, v[i] - k);
    r = min(n, v[i] + k);
    maxm = maxquery(l, r + 1);
    dp[i] += maxm;
    if (st[v[i] + n] < dp[i]) update(v[i], dp[i]);
  }
  cout << dp[n - 1] << endl;
  return 0;
}
