#include <bits/stdc++.h>
using namespace std;
const int MAXN = 30010;
const int MAX = 2000;
const int CUP = 1900;
int n, d;
int a[MAXN];
int dp[MAXN][MAX];
int ans = 0;
int g(int x) {
  if (x < MAXN)
    return a[x];
  else
    return 0;
}
void brute(int x, int prev, int res = 0) {
  if (x >= MAXN) {
    ans = max(ans, res);
    return;
  }
  if (prev == 0) {
    return;
  }
  brute(x + prev, prev, res + a[x]);
  brute(x + prev - 1, prev - 1, res + a[x]);
  brute(x + prev + 1, prev + 1, res + a[x]);
}
int dyn(int n, int k) {
  cout << n << " " << k << endl;
  if (n >= MAXN) {
    return 0;
  }
  if (dp[n][k] != -1) {
    return dp[n][k];
  }
  dp[n][k] = 0;
  dp[n][k] = max(dyn(n + k, k), dp[n][k]);
  dp[n][k] = max(dyn(n + k + 1, k + 1), dp[n][k]);
  dp[n][k] = max(dyn(n + k - 1, k - 1), dp[n][k]);
  dp[n][k] += g(n);
  return dp[n][k];
}
int main() {
  cin >> n >> d;
  for (int i = 0; i < n; i++) {
    int t;
    cin >> t;
    a[t]++;
  }
  if (d > CUP) {
    brute(d, d, 0);
  } else {
    for (int i = MAXN - 1; i >= d; i--) {
      for (int j = 1; j < MAX; j++) {
        if (i + j < MAXN) dp[i][j] = max(dp[i][j], dp[i + j][j]);
        if (i + j + 1 < MAXN && j + 1 < MAX)
          dp[i][j] = max(dp[i][j], dp[i + j + 1][j + 1]);
        if (i + j - 1 < MAXN) dp[i][j] = max(dp[i][j], dp[i + j - 1][j - 1]);
        dp[i][j] += a[i];
      }
    }
    ans = dp[d][d];
  }
  cout << ans;
  return 0;
}
