#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0, f = 1;
  char ch = 0;
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') f = -1;
  for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - 48;
  return x * f;
}
const int MAXN = 3e4 + 5;
const int MAXD = 500;
int n, d, x, offset, dp[MAXN][MAXD], a[MAXN];
int g(int i, int j) {
  if (i <= 30000) return dp[i][j - offset];
  return 0;
}
int main() {
  std::ios::sync_with_stdio(false);
  n = read(), d = read();
  offset = max(0, d - 246);
  for (int _ = 1; _ <= n; _++) x = read(), a[x]++;
  for (int i = 30000; i >= d; i--)
    for (int j = max(1, d - 245); j <= d + 245; j++) {
      dp[i][j - offset] = a[i] + max(g(i + j, j), g(i + j + 1, j + 1));
      if (j > 1)
        dp[i][j - offset] = max(dp[i][j - offset], a[i] + g(i + j - 1, j - 1));
    }
  cout << dp[d][d - offset];
}
