#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
using namespace std;
struct cmp {
  long long int val = -1;
};
map<long long int, map<long long int, cmp> > dp;
long long int go(vector<long long int> &arr, long long int i, long long int n,
                 long long int last, long long int k) {
  if (i == n) return 0;
  long long int a = 0, b = 0;
  if (dp[i][last].val != -1) return dp[i][last].val;
  if (last == -1) {
    a = go(arr, i + 1, n, last, k);
    b = 1 + go(arr, i + 1, n, arr[i], k);
  } else {
    if (abs(arr[i] - last) <= k) {
      a = go(arr, i + 1, n, last, k);
      b = 1 + go(arr, i + 1, n, arr[i], k);
    } else
      a = go(arr, i + 1, n, last, k);
  }
  return dp[i][last].val = max(a, b);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int i, j, ans = 0, n, k;
  cin >> n >> k;
  vector<long long int> arr(n);
  map<long long int, long long int> m1;
  for (i = 0; i < n; i++) {
    cin >> arr[i];
    m1[arr[i]] += 1;
  }
  long long int high = INT_MIN;
  for (auto it : m1) high = max(high, it.second);
  if (k == 0) {
    cout << high << endl;
    return 0;
  }
  cout << go(arr, 0, n, -1, k) << endl;
  return 0;
}
