#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, K;
  cin >> N >> K;
  vector<int> count(N + 1, 0);
  for (int i = 0; i < N; i++) {
    int A;
    cin >> A;
    int min_i = A - K;
    int max_i = A + K;
    if (min_i <= 0) {
      min_i = 1;
    }
    if (max_i > N) {
      max_i = N;
    }
    count[min_i]++;
    count[max_i]--;
  }
  int ans = count[1];
  for (int i = 2; i <= N; i++) {
    count[i] += count[i - 1];
    if (count[i] > ans) {
      ans = count[i];
    }
  }
  cout << ans << endl;
}
