#include <bits/stdc++.h>
template <typename T>
struct LazySegmentTree {
 private:
  int n;
  T init;
  std::vector<T> node;
  std::vector<T> lazy;

 public:
  explicit LazySegmentTree(int sz, T initv = 0) {
    n = 1;
    init = initv;
    while (n < sz) n = n * 2;
    node.resize(static_cast<unsigned int>(2 * n - 1), init);
    for (int i = 0; i < sz; ++i) node[i + n - 1] = init;
    for (int i = n - 2; i >= 0; --i)
      node[i] = std::max(node[2 * i + 1], node[2 * i + 2]);
    lazy.resize(static_cast<unsigned int>(2 * n - 1), init);
    for (int i = 0; i < sz; ++i) lazy[i + n - 1] = init;
    for (int i = n - 2; i >= 0; --i)
      lazy[i] = std::max(lazy[2 * i + 1], lazy[2 * i + 2]);
  }
  void add(int p, int q, T val, int k = 0, int l = 0, int r = -1) {
    if (r < 0) r = n;
    update(k);
    if (r <= p || l >= q) return;
    if (p <= l && r <= q) {
      lazy[k] += val;
      update(k);
    } else {
      add(p, q, val, 2 * k + 1, l, (l + r) / 2);
      add(p, q, val, 2 * k + 2, (l + r) / 2, r);
      node[k] = std::max(node[2 * k + 1], node[2 * k + 2]);
    }
  }
  T getmax(int p, int q, int k = 0, int l = 0, int r = -1) {
    if (r < 0) r = n;
    if (r <= p || l >= q) return 0;
    update(k);
    if (p <= l && r <= q) return node[k];
    T vl = getmax(p, q, 2 * k + 1, l, (l + r) / 2);
    T vr = getmax(p, q, 2 * k + 2, (l + r) / 2, r);
    return std::max(vl, vr);
  }
  void update(int k) {
    if (lazy[k] != 0) {
      node[k] += lazy[k];
      if (k < n - 1) {
        lazy[2 * k + 1] += lazy[k];
        lazy[2 * k + 2] += lazy[k];
      }
      lazy[k] = 0;
    }
  }
};
using namespace std;
using ll = long long;
int main() {
  int n, k;
  cin >> n >> k;
  LazySegmentTree<ll> st(300001 + k);
  for (int i = 0; i < n; ++i) {
    int a;
    cin >> a;
    st.add(a - k, a + k, 1);
  }
  cout << st.getmax(0, 300001 + k) << endl;
  return 0;
}
