#include <bits/stdc++.h>
using namespace std;
const int N = 3e4 + 5;
const int OFFSET = 250;
int dp[N][505];
int is_valid[N];
int n_ilhas, salto;
int solve(int where, int off) {
  if (where >= N) return 0;
  int &res = dp[where][off + OFFSET];
  if (~res) return res;
  int nxt = where + salto + off;
  res = 0;
  if (nxt + 1 > where) res = max(res, solve(nxt + 1, off + 1));
  if (nxt > where) res = max(res, solve(nxt, off));
  if (nxt - 1 > where) res = max(res, solve(nxt - 1, off - 1));
  return res += is_valid[where];
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n_ilhas >> salto;
  memset(dp, -1, sizeof(dp));
  for (int i = 0; i < n_ilhas; i++) {
    int foo;
    cin >> foo;
    is_valid[foo]++;
  }
  cout << solve(salto, 0) << '\n';
  return 0;
}
