#include <bits/stdc++.h>
using namespace std;
const int base = 100003;
const int maxn = 600005;
int n, k, a[maxn];
long long tree[8 * maxn], dp[maxn];
int Get(int node, int l, int r, int u, int v) {
  if (u > r || l > v) return 0;
  if (l >= u && r <= v) return tree[node];
  int mid = (l + r) >> 1;
  int L = Get(node * 2, l, mid, u, v);
  int R = Get(node * 2 + 1, mid + 1, r, u, v);
  return max(L, R);
}
void Update(int node, int l, int r, int id, long long val) {
  if (l == r) {
    tree[node] += val;
    return;
  }
  int mid = (l + r) >> 1;
  if (id <= mid)
    Update(node * 2, l, mid, id, val);
  else
    Update(node * 2 + 1, mid + 1, r, id, val);
  tree[node] = max(tree[node * 2], tree[node * 2 + 1]);
}
void Solve() {
  cin >> n >> k;
  int mx = 0;
  for (int i = 1; i <= n; ++i) cin >> a[i];
  for (int i = 1; i <= n; ++i) {
    int l = max(0, a[i] - k);
    int r = min(a[i] + k, maxn);
    long long res = Get(1, 1, maxn, l, r);
    dp[i] = max(dp[i], res + 1);
    Update(1, 1, maxn, a[i], dp[i]);
  }
  long long ans = 1;
  for (int i = 1; i <= n; ++i) ans = max(ans, dp[i]);
  cout << ans;
}
void NumTime() {
  cerr << "Toi"
       << "\n";
  cerr << "Di"
       << "\n";
  cerr << "Chep"
       << "\n";
  cerr << "Code"
       << "\n";
}
int main() {
  ios_base::sync_with_stdio(0);
  cout.tie(0);
  cin.tie(0);
  if (fopen("CF"
            ".inp",
            "r")) {
    freopen(
        "CF"
        ".inp",
        "r", stdin);
    freopen(
        "CF"
        ".out",
        "w", stdout);
  }
  int test = 1;
  while (test--) {
    NumTime();
    Solve();
  }
}
