#include <bits/stdc++.h>
using namespace std;
vector<string> vec_splitter(string s) {
  s += ',';
  vector<string> res;
  while (!s.empty()) {
    res.push_back(s.substr(0, s.find(',')));
    s = s.substr(s.find(',') + 1);
  }
  return res;
}
void debug_out(vector<string> __attribute__((unused)) args,
               __attribute__((unused)) int idx,
               __attribute__((unused)) int LINE_NUM) {
  cerr << endl;
}
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
  if (idx > 0)
    cerr << ", ";
  else
    cerr << "Line(" << LINE_NUM << ") ";
  stringstream ss;
  ss << H;
  cerr << args[idx] << " = " << ss.str();
  debug_out(args, idx + 1, LINE_NUM, T...);
}
const double PI = 3.14159265358979323846;
const double eps = (1e-8);
int isGreater(long double x, long double y) {
  if (abs(x - y) < eps) return 0;
  if (x > y) return 1;
  return -1;
}
const int MAX_N = 3e4 + 5, MAX_ADD = 200, NUM_ISLANDS = 30001;
int a[MAX_N], n, d;
int mem[MAX_N][2 * MAX_ADD + 1];
int solve(int i, int add) {
  int &ret = mem[i][add + MAX_ADD];
  if (~ret) return ret;
  ret = 0;
  for (int j = -1; j <= 1; ++j) {
    int to = i + d + add + j;
    if (to > i && to < NUM_ISLANDS) ret = max(ret, solve(to, add + j));
  }
  ret += a[i];
  return ret;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> d;
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    a[x]++;
  }
  memset(mem, -1, sizeof(mem));
  cout << solve(d, 0) << '\n';
}
