#include <bits/stdc++.h>
using namespace std;
int dp[32005][1005];
int gems[30005];
int stuff(int i, int j) {
  if (i >= 30001) return 0;
  return dp[i][j];
}
int main() {
  int n, d;
  cin >> n >> d;
  for (int i = 0; i < 30005; ++i)
    for (int j = 0; j < 1005; ++j) dp[i][j] = 0;
  for (int i = 0; i < 30005; ++i) gems[i] = 0;
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    gems[x]++;
  }
  if (d > 500) {
    for (int i = 30000; i >= 0; --i)
      for (int j = 1; j <= 1000; ++j) {
        dp[i][j] =
            max(stuff(i + d - 500 + j, j), stuff(i + d - 500 + j + 1, j + 1));
        dp[i][j] = max(dp[i][j], stuff(i + d - 500 + j - 1, j - 1));
        dp[i][j] += gems[i];
      }
    cout << dp[d][500] << endl;
  } else {
    for (int i = 30000; i >= 0; --i)
      for (int j = 1; j <= 1000; ++j) {
        dp[i][j] = max(stuff(i + j, j), stuff(i + j + 1, j + 1));
        if (j > 1) dp[i][j] = max(stuff(i + j - 1, j - 1), dp[i][j]);
        dp[i][j] += gems[i];
      }
    cout << dp[d][d] << endl;
  }
}
