#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3f;
const int eps = 1e-9;
inline int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
inline int lcm(int a, int b) { return a * b / gcd(a, b); }
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = (x << 1) + (x << 3) + (ch ^ 48);
    ch = getchar();
  }
  return x * f;
}
const int maxn = 3e5 + 50;
int n, k;
long long dp[maxn], a[maxn];
int main() {
  cin >> n >> k;
  memset(dp, 0, sizeof dp);
  memset(a, 0, sizeof a);
  for (int i = 1; i <= n; ++i) {
    int x;
    cin >> x;
    dp[max(x - k, 1)]++;
    if (x + k + 1 <= n) dp[x + k + 1]--;
  }
  long long maxx = 0;
  for (int i = 1; i <= n; ++i) {
    dp[i] = dp[i - 1] + dp[i];
    maxx = max(maxx, dp[i]);
  }
  cout << maxx - 1 << endl;
  return 0;
}
