#include <bits/stdc++.h>
using namespace std;
int seg[4 * int(100)], lazy[4 * int(100)], v;
void build(int l, int h, int pos) {
  if (l == h) {
    seg[pos] = lazy[pos] = 0;
    return;
  }
  int mid = (l + h) / 2;
  build(l, mid, 2 * pos);
  build(mid + 1, h, 2 * pos + 1);
  seg[pos] = lazy[pos] = 0;
}
void update(int l, int h, int x, int y, int pos) {
  if (lazy[pos]) {
    seg[pos] = lazy[pos];
    if (l != h) {
      lazy[2 * pos] = lazy[pos];
      lazy[2 * pos + 1] += lazy[pos];
    }
    lazy[pos] = 0;
  }
  if (h < x || l > y) return;
  if (x <= l && h <= y) {
    seg[pos] = v;
    if (l != h) {
      lazy[2 * pos] = v;
      lazy[2 * pos + 1] = v;
    }
    return;
  }
  int mid = (l + h) / 2;
  update(l, mid, x, y, 2 * pos);
  update(mid + 1, h, x, y, 2 * pos + 1);
  seg[pos] = max(seg[2 * pos], seg[2 * pos + 1]);
}
int query(int l, int h, int x, int pos) {
  if (lazy[pos]) {
    seg[pos] = lazy[pos];
    if (l != h) {
      lazy[2 * pos] = lazy[pos];
      lazy[2 * pos + 1] = lazy[pos];
    }
    lazy[pos] = 0;
  }
  if (h < x || l > x) return 0;
  if (l == h) {
    return seg[pos];
  }
  int mid = (l + h) / 2;
  int q1 = query(l, mid, x, 2 * pos);
  int q2 = query(mid + 1, h, x, 2 * pos + 1);
  return max(q1, q2);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cout.precision(10);
  int n, k;
  cin >> n >> k;
  int a[n + 1], dp[n + 1];
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    a[i]++;
  }
  int g[n + 1], s[n + 1];
  for (int i = 1; i <= n; i++) {
    s[i] = query(1, int(100), a[i], 1);
    v = i;
    update(1, int(100), a[i], min(int(100) - 1, a[i] + k), 1);
  }
  build(1, int(100), 1);
  for (int i = 1; i <= n; i++) {
    g[i] = query(1, int(100), a[i], 1);
    v = i;
    update(1, int(100), max(1, a[i] - k), a[i], 1);
  }
  for (int i = 1; i <= n; i++) {
    dp[i] = 1;
    if (s[i]) dp[i] = max(dp[i], dp[s[i]] + 1);
    if (g[i]) dp[i] = max(dp[i], dp[g[i]] + 1);
  }
  cout << *max_element(dp + 1, dp + n + 1) << endl;
  return 0;
}
