#include <bits/stdc++.h>
using namespace std;
const int N = 4e4 + 50;
const int N1 = 4e2 + 50;
const int P = 6e6;
const int S = 30000;
int a[N], dp[N][N1];
int main() {
  int n, d;
  cin >> n >> d;
  int ma = d, cur = S - d;
  while (cur - (ma + 1) >= 0) {
    ma++;
    cur -= ma;
  }
  int mi = d;
  cur = S - d;
  while ((mi - 1) > 0 && cur - (mi - 1) >= 0) {
    mi--;
    cur -= mi;
  }
  for (int i = 0; i < n; i++) {
    int p;
    cin >> p;
    a[p]++;
  }
  for (int i = 0; i <= S; i++)
    for (int j = 0; mi + j <= ma; j++) dp[i][j] = -1;
  dp[d][d - mi] = a[d];
  int res = dp[d][d - mi];
  for (int i = d + 1; i <= S; i++) {
    for (int j = 0; mi + j <= min(i, ma); j++) {
      dp[i][j] = max(dp[i][j], dp[i - j - mi][j]);
      if (mi + j < ma) dp[i][j] = max(dp[i][j], dp[i - j - mi][j + 1]);
      if (j > 0) dp[i][j] = max(dp[i][j], dp[i - j - mi][j - 1]);
      if (dp[i][j] != -1) dp[i][j] += a[i];
      res = max(res, dp[i][j]);
    }
  }
  cout << res << endl;
  return 0;
}
