#include<bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;

#define MOD 1000000007
#define MOD99 998244353
 
int main(){
  int n,k,maxi = 0;
  cin >> n >> k;
  vector<int> a(n),numbers(300001,0);
  for(int i = 0;i < n;i++){
    cin >> a[i];
    numbers[a[i]]++;
  }

  for(int i = 1;i <= 300000;i++){
    numbers[i] += numbers[i - 1];
  }
   for(int i = k;i <= 300000 - k + 1;i++){
     maxi = max(maxi,numbers[i + k] - numbers[i - k]);
  }
  cout << maxi << endl;
}