#include <bits/stdc++.h>
using namespace std;
struct dsu {
  vector<long long> parent;
  vector<long long> rank;
  long long comp;
  void init(long long n) {
    parent.resize(n + 1);
    rank.resize(n + 1);
    for (long long p = 1; p <= n; p++) {
      parent[p] = p;
      rank[p] = 1;
    }
    comp = n;
  }
  long long f(long long x) {
    if (parent[x] == x) return x;
    return parent[x] = f(parent[x]);
  }
  void mer(long long a, long long b) {
    a = f(a);
    b = f(b);
    if (rank[a] < rank[b]) {
      rank[b] += rank[a];
      parent[a] = b;
    } else {
      rank[a] += rank[b];
      parent[b] = a;
    }
    comp--;
  }
} G;
long long a[3000001];
long long dp[3000001];
int main() {
  long long n, k;
  cin >> n >> k;
  for (long long p = 0; p < n; p++) {
    cin >> a[p];
    dp[p] = 1;
  }
  long long ans = 1;
  for (long long p = 1; p < n; p++) {
    for (long long h = 0; h < p; h++) {
      long long cur_len = dp[p];
      if ((abs(a[h] - a[p])) <= k) {
        cur_len = dp[h] + 1;
      }
      dp[p] = max(dp[p], cur_len);
    }
    ans = max(ans, dp[p]);
  }
  cout << ans;
}
