#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const long long int INFF = 1e17;
const double EPS = 1e-9;
const long long int MOD = 1e9 + 7;
const int MAXN = 3e4 + 1;
int n, d, a[MAXN + 1], dp[MAXN + 1][500];
int f(int curr, int jump) {
  if (curr >= MAXN) return 0;
  if (dp[curr][jump - d + 245] != -1) return dp[curr][jump - d + 245];
  dp[curr][jump - d + 245] = 0;
  if (jump > 1)
    dp[curr][jump - d + 245] =
        max(dp[curr][jump - d + 245], a[curr] + f(curr + jump - 1, jump - 1));
  if (jump > 0)
    dp[curr][jump - d + 245] =
        max(dp[curr][jump - d + 245], a[curr] + f(curr + jump, jump));
  if (jump > -1)
    dp[curr][jump - d + 245] =
        max(dp[curr][jump - d + 245], a[curr] + f(curr + jump + 1, jump + 1));
  return dp[curr][jump - d + 245];
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> d;
  for (int i = (0); i < (MAXN + 1); ++i) a[i] = 0;
  for (int i = (0); i < (n); ++i) {
    int t1;
    cin >> t1;
    a[t1]++;
  }
  for (int i = (0); i < (MAXN + 1); ++i)
    for (int j = (0); j < (500); ++j) dp[i][j] = -1;
  cout << f(d, d) << '\n';
  return 0;
}
