#include <bits/stdc++.h>
using namespace std;
template <class _T>
inline string tostr(const _T& a) {
  ostringstream os("");
  os << a;
  return os.str();
}
const int maxn = 31000;
const int off = 300;
const int maxm = 2 * off;
int dp[maxn][maxm + 10];
int gem[maxn];
int n, d, maxpos;
int main() {
  cin >> n >> d;
  for (int(i) = (0); (i) < (n); ++(i)) {
    int aux;
    cin >> aux;
    gem[aux]++;
    maxpos = max(maxpos, aux);
  }
  for (int pos = maxpos + 1; pos > 0; pos--) {
    for (int(l) = (0); (l) < (maxm); ++(l)) {
      for (int(i) = (0); (i) < (3); ++(i)) {
        int jump = d + (l - off) + i - 1;
        int npos = pos + jump;
        if (npos < maxn && jump > 0 && l + i - 1 > 0) {
          dp[pos][l] = max(dp[pos][l], dp[npos][l + i - 1]);
        }
      }
      dp[pos][l] += gem[pos];
    }
  }
  cout << dp[d][off] << endl;
  return 0;
}
