#include <bits/stdc++.h>
using namespace std;
const int N = 30001;
int M, D;
int A[N];
int dp[N + 1][1900];
int dfs(int x, int l) {
  int s = 0;
  for (int k = l - 1; k <= l + 1; k++) {
    if (x + k < N && k > 0) s = max(s, dfs(x + k, k));
  }
  return s + A[x];
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> M >> D;
  for (int i = 0; i < (M); i++) {
    int a;
    cin >> a;
    A[a]++;
  }
  if (D >= 1800) {
    cout << dfs(D, D) << "\n";
  } else {
    for (int i = 0; i < (N + 1); i++)
      for (int j = 0; j < (1900); j++) dp[i][j] = -1145141919;
    dp[D][D] = A[D];
    for (int i = D; i < N; i++) {
      for (int j = 0; j < (1900); j++) {
        if (dp[i][j] == -1145141919) continue;
        for (int k = j - 1; k <= j + 1; k++) {
          if (i + k >= N || k <= 0 || k >= 1900) continue;
          dp[i + k][k] = max(dp[i + k][k], dp[i][j] + A[i + k]);
        }
      }
    }
    int m = 0;
    for (int i = 0; i < (N + 1); i++)
      for (int j = 0; j < (1900); j++) m = max(m, dp[i][j]);
    cout << m << "\n";
  }
  return 0;
}
