#include <bits/stdc++.h>
using namespace std;
constexpr long long int dx[] = {-1, 0, 1, 0, 1, 1, -1, -1};
constexpr long long int dy[] = {0, -1, 0, 1, 1, -1, 1, -1};
constexpr long long ll INF = 1999999999999999997;
constexpr long long int inf = INT_MAX;
constexpr long long int MAXSIZE = long long int(2e6) + 5;
constexpr auto PI = 3.14159265358979323846L;
constexpr auto eps = 1e-6;
constexpr auto mod = 1000000007;
constexpr auto maxn = 100006;
void fastio() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}
long long int tree[MAXSIZE];
long long int lazy[MAXSIZE];
long long int a[MAXSIZE];
void build(long long int node, long long int left, long long int right) {
  if (left == right) {
    tree[node] = a[left];
    return;
  }
  long long int mid = (left + right) / 2;
  build(2 * node, left, mid);
  build(2 * node + 1, mid + 1, right);
  tree[node] = max(tree[2 * node], tree[2 * node + 1]);
}
void propogate(long long int node, long long int left, long long int right) {
  if (lazy[node] != 0) {
    tree[node] = max(tree[node], lazy[node]);
    if (left != right) {
      lazy[2 * node] += lazy[node];
      lazy[2 * node + 1] += lazy[node];
    }
    lazy[node] = 0;
  }
}
void update(long long int node, long long int left, long long int right,
            long long int l, long long int r, long long int val) {
  if (left > r || right < l || right < left) return;
  if (left >= l and right <= r) {
    tree[node] = max(tree[node], val);
    return;
  }
  long long int mid = (left + right) / 2;
  update(2 * node, left, mid, l, r, val);
  update(2 * node + 1, mid + 1, right, l, r, val);
  tree[node] = max(tree[2 * node], tree[2 * node + 1]);
}
long long int query(long long int node, long long int left, long long int right,
                    long long int l, long long int r) {
  if (left > r || right < l || right < left) return 0;
  if (left >= l and right <= r) return tree[node];
  long long int mid = (left + right) / 2;
  long long int p = query(2 * node, left, mid, l, r);
  long long int q = query(2 * node + 1, mid + 1, right, l, r);
  return max(p, q);
}
long long int dp[2][3 * maxn];
int32_t main() {
  fastio();
  long long int n, k;
  cin >> n >> k;
  long long int ans = 0;
  build(1, 1, 3 * maxn);
  for (long long int i = 1; i <= n; i++) {
    long long int x;
    cin >> x;
    long long int l =
        query(1, 1, 3 * maxn, max(1ll, x - k), min(3ll * maxn, x + k));
    ans = max(ans, 1 + l);
    update(1, 1, 3 * maxn, x, x, 1 + l);
  }
  cout << ans;
}
