#include <bits/stdc++.h>
using namespace std;
long long spf[1000005];
vector<long long> primes, prev[1000005], next[1000005];
set<long long> s;
void sieve() {
  for (long long i = 2; i < 1000005; ++i) {
    if (spf[i] == 0) {
      spf[i] = i;
      for (long long j = 2 * i; j <= 1000005; j += i) {
        if (spf[j] == 0) spf[j] = i;
      }
    }
  }
}
void SieveOfEratosthenes(long long n) {
  bool prime[n + 1];
  memset(prime, true, sizeof(prime));
  for (long long p = 2; p * p <= n; p++) {
    if (prime[p] == true) {
      for (long long i = p * 2; i <= n; i += p) prime[i] = false;
    }
  }
  for (long long p = 2; p <= n; p++) {
    if (prime[p]) {
      primes.push_back(p);
      s.insert(p);
    }
  }
}
bool cmp(const pair<long long, long long>& a,
         const pair<long long, long long>& b) {
  if (a.first == b.first)
    return a.second < b.second;
  else
    return a.first > b.first;
}
void dfs(long long u, vector<long long> g[], bool vis[]) {
  if (!vis[u]) {
    vis[u] = 1;
  }
  for (auto i : g[u]) {
    if (!vis[i]) dfs(i, g, vis);
  }
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  srand(static_cast<unsigned>(time(0)));
  SieveOfEratosthenes(1000005);
  long long t = 1;
  while (t--) {
    long long n, k;
    cin >> n >> k;
    vector<long long> a(n);
    for (long long i = 0; i < n; ++i) cin >> a[i];
    long long dp[n];
    dp[0] = 1;
    for (long long i = 1; i < n; ++i) {
      dp[i] = 1;
      for (long long j = 0; j < i; ++j) {
        if (abs(a[i] - a[j]) <= k) dp[i] = max(dp[i], dp[j] + 1);
      }
    }
    long long res = dp[0];
    for (long long i = 0; i < n; ++i) res = max(res, dp[i]);
    cout << res << '\n';
  }
  return 0;
}
