#include <bits/stdc++.h>
using namespace std;
long long k, tree[2000020], b[500005], x, n;
int ans = 0;
long long query(int node, int s, int e, int l, int r) {
  if (r < s || e < l) return 0LL;
  if (s >= l && e <= r) return tree[node];
  int m = (s + e) / 2;
  return (query(2 * node, s, m, l, r) % 1000000007 +
          query(2 * node + 1, m + 1, e, l, r) % 1000000007) %
         1000000007;
}
void update(int node, int s, int e, int idx, long long val) {
  if (s == e) {
    tree[node] = val;
    return;
  }
  int m = (s + e) / 2;
  if (idx <= m)
    update(2 * node, s, m, idx, val);
  else
    update(2 * node + 1, m + 1, e, idx, val);
  tree[node] = (tree[2 * node] % 1000000007 + tree[2 * node + 1] % 1000000007) %
               1000000007;
}
int main() {
  cin >> n >> k;
  vector<pair<long long, long long> > a;
  for (int i = 0; i < n; i++) {
    cin >> x;
    a.push_back(make_pair(x, i));
    b[i] = a[i].first;
  }
  sort(a.begin(), a.end());
  for (long long int i = 0; i < n; i++) {
    int l =
        lower_bound(a.begin(), a.end(), make_pair(b[i] - k, 0LL)) - a.begin();
    int r = (upper_bound(a.begin(), a.end(), make_pair(b[i] + k, n + 1LL)) -
             a.begin()) -
            1;
    if (l < n && r < n && l <= r) {
      long long dd = query(1, 0, n - 1, l, r);
      ans = max(ans, r - l);
      update(1, 0, n - 1,
             lower_bound(a.begin(), a.end(), make_pair(b[i], i)) - a.begin(),
             (dd + 1LL) % 1000000007);
    }
  }
  cout << ans << endl;
}
