#include <bits/stdc++.h>
using namespace std;
template <class T>
void debug(T itr1, T itr2) {
  auto now = itr1;
  while (now < itr2) {
    cout << *now << " ";
    now++;
  }
  cout << endl;
}
const long long MOD = pow(10, 9) + 7;
const long long LLINF = pow(2, 61) - 1;
const long long INF = pow(2, 30) - 1;
vector<long long> fac;
void c_fac(long long x = pow(10, 6) + 10) {
  fac.resize(x, true);
  for (long long i = (long long)0; i < (long long)x; i++)
    fac[i] = i ? (fac[i - 1] * i) % MOD : 1;
}
long long inv(long long a, long long m = MOD) {
  long long b = m, x = 1, y = 0;
  while (b != 0) {
    long long d = a / b;
    a -= b * d;
    swap(a, b);
    x -= y * d;
    swap(x, y);
  }
  return (x + m) % m;
}
long long nck(long long n, long long k) {
  return fac[n] * inv(fac[k] * fac[n - k] % MOD) % MOD;
}
long long modpow(long long x, long long p) {
  long long result = 1, now = 1, pm = x;
  while (now <= p) {
    if (p & now) {
      result = result * pm % MOD;
    }
    now *= 2;
    pm = pm * pm % MOD;
  }
  return result;
}
long long gcd(long long a, long long b) {
  if (a < b) swap(a, b);
  return b == 0 ? a : gcd(b, a % b);
}
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
struct SegTree {
  long long size;
  vector<long long> pos;
  SegTree(long long N) {
    size = 1;
    while (size < N) size <<= 1;
    pos.resize(2 * size, 0);
  }
  long long operator[](const long long &x) const { return pos[x + size]; }
  void set(long long x, const long long v) { pos[x + size] = v; }
  void update(long long x, const long long v) {
    set(x, v);
    x += size;
    while (x >>= 1) operate(x);
  }
  long long query(long long a, long long b) {
    long long L = 0, R = 0;
    for (a += size, b += size; a < b; a >>= 1, b >>= 1) {
      if (a & 1) {
        L = q(L, pos[a]);
        a++;
      }
      if (b & 1) {
        b--;
        R = q(pos[b], R);
      }
    }
    return q(L, R);
  }
  void operate(long long i) { pos[i] = q(pos[i * 2], pos[i * 2 + 1]); }
  long long q(long long x, long long y) { return max(x, y); }
};
int main() {
  long long N, K;
  cin >> N >> K;
  long long A[N];
  for (long long i = (long long)0; i < (long long)N; i++) cin >> A[i];
  long long MA = 10;
  SegTree st(MA);
  for (long long i = (long long)0; i < (long long)N; i++) {
    st.update(A[i],
              st.query(max(0ll, A[i] - K), min(MA - 1, A[i] + K) + 1) + 1);
  }
  long long result = st.query(0, MA);
  cout << result << endl;
  return 0;
}
