#include <bits/stdc++.h>
using namespace std;
long long int arr[500005], n;
vector<pair<long long int, long long int> > v;
long long int lower(long long int x) {
  long long int l = 0, h = n - 1, mid, ans = 0;
  while (l <= h) {
    mid = (l + h) / 2;
    if (v[mid].first >= x) {
      ans = mid;
      h = mid - 1;
    } else
      l = mid + 1;
  }
  return ans;
}
long long int upper(long long int x) {
  long long int l = 0, h = n - 1, mid, ans = n - 1;
  while (l <= h) {
    mid = (l + h) / 2;
    if (v[mid].first <= x) {
      ans = mid;
      l = mid + 1;
    } else
      h = mid - 1;
  }
  return ans;
}
int main() {
  long long int i, b, a, k, sum = 0;
  cin >> n >> k;
  for (i = 0; i < n; i++) {
    cin >> arr[i];
    v.push_back(make_pair(arr[i], i));
  }
  sort(v.begin(), v.end());
  long long int ans = 0;
  for (i = n - 1; i >= 0; i--) {
    a = lower(arr[i] - k);
    b = upper(arr[i] + k);
    ans = max(ans, b - a);
  }
  cout << ans << endl;
  return 0;
}
