#include <bits/stdc++.h>
using namespace std;
template <class S>
S sum(vector<S>& a) {
  return accumulate(a.begin(), a.end(), S());
}
template <class S>
S max(vector<S>& a) {
  return *max_element(a.begin(), a.end());
}
template <class S>
S min(vector<S>& a) {
  return *min_element(a.begin(), a.end());
}
long long max(int a, long long b) { return max((long long)a, b); }
long long max(long long a, int b) { return max(a, (long long)b); }
long long min(int a, long long b) { return min((long long)a, b); }
long long min(long long a, int b) { return min(a, (long long)b); }
void eprint() { cerr << endl; }
template <class First, class... Rest>
void eprint(First& f, Rest&... r) {
  cerr << f << ' ';
  eprint(r...);
}
template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
  size_t output_num = v.size();
  bool is_omitted = false;
  os << "[";
  for (size_t i = 0; i < output_num - 1; i++) os << v[i] << ", ";
  os << v[output_num - 1];
  if (is_omitted) os << ", ...";
  return os << "]";
}
void Main();
int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  Main();
  return 0;
}
void Main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (long long i = 0; i < (long long)(n); i++) cin >> a[i];
  vector<int> dp(n, 1);
  for (int i = n - 1; i >= 0; i--) {
    for (int j = i + 1; j < n; j++) {
      if (abs(a[i] - a[j]) <= k) {
        dp[i] = max(dp[i], dp[j] + 1);
      }
    }
  }
  cout << max(dp) << endl;
}
