#include <bits/stdc++.h>
using namespace std;
template <typename T1, typename T2>
ostream &operator<<(ostream &out, pair<T1, T2> a) {
  return (out << "(" << a.first << "; " << a.second << ")");
}
template <typename T1>
ostream &operator<<(ostream &cout, vector<T1> &a) {
  cout << "(";
  for (int i = 0; i < (int)a.size(); i++) cout << a[i] << "; ";
  cout << ")";
  return cout;
}
const int nmax = 30001;
const int del = 600;
const int inf = 1000 * 1000 * 1000;
const int mod = 1000 * 1000 * 1000 + 7;
const int pi = acos(-1.0);
const long long infl = 1000ll * 1000ll * 1000ll * 1000ll * 1000ll * 1000ll;
int n, d, a[nmax], dp[nmax][2 * del], x;
int main() {
  assert(scanf("%d%d", &n, &d));
  for (int i = 0; i < n; i++) {
    assert(scanf("%d", &x));
    a[x]++;
  }
  for (int i = 0; i < nmax; i++)
    for (int j = 0; j < del * 2; j++) dp[i][j] = -1;
  dp[d][del] = a[d];
  int answer = 0;
  for (int i = 0; i < nmax; i++) {
    for (int j = 0; j < del * 2; j++) {
      if (dp[i][j] == -1) continue;
      for (int q = -1; q < 2; q++) {
        int dx = d + j - del + q;
        if (dx > 0 && i + dx < nmax && j + q >= 0 && j + q < del * 2)
          dp[i + dx][j + q] = max(dp[i + dx][j + q], dp[i][j] + a[i + dx]);
      }
      answer = max(answer, dp[i][j]);
    }
  }
  cout << answer << endl;
}
