#include <bits/stdc++.h>
using namespace std;
const long double EPS = 1e-11;
int n, d;
const int M = 30001;
int f[M][250 * 2];
int v[M];
int solve(int i, int j) {
  if (i >= M) return 0;
  int jj = j - (d - 250);
  if (f[i][jj] != -1) return f[i][jj];
  f[i][jj] = 0;
  int res = 0;
  if (j == 1)
    res += max(solve(i + j, j), solve(i + j + 1, j + 1)) + v[i];
  else
    res += max(solve(i + j - 1, j - 1),
               max(solve(i + j, j), solve(i + j + 1, j + 1))) +
           v[i];
  return f[i][jj] = res;
}
int main() {
  ios_base::sync_with_stdio(false);
  for (int i = 0; i < (int)M; i++)
    for (int j = 0; j < (int)250 * 2; j++) f[i][j] = -1;
  cin >> n >> d;
  for (int i = 0; i < (int)n; i++) {
    int j;
    cin >> j;
    v[j]++;
  }
  cout << solve(d, d) << endl;
  return 0;
}
