#include <bits/stdc++.h>
using namespace std;
const int N = 3e4 + 1;
const int K = 400;
int a[N + 1];
const int INF = 1e9;
int dp[N + 1][2 * K];
int n, d, res;
int rec(int i, int j) {
  if (i < d || j <= 0 || j >= K + d) return -INF;
  int jj = j + K - d;
  if (jj < 0 || jj >= 2 * K) return -INF;
  if (dp[i][jj] != -1) return dp[i][jj];
  int &ans = dp[i][jj];
  ans = -INF;
  ans = max({ans, rec(i - j, j + 1), rec(i - j, j)});
  if (j > 1) ans = max(ans, rec(i - j, j - 1));
  ans += a[i];
  res = max(ans, res);
  return ans;
}
signed main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> n >> d;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    a[x]++;
  }
  memset(dp, -1, sizeof dp);
  res = dp[d][K] = a[d];
  for (int i = d; i <= N; i++)
    for (int j = d - K; j < d + K; j++) res = max(res, rec(i, j));
  cout << res << '\n';
}
