#include <bits/stdc++.h>
using namespace std;
int g[30004], d, dp[30004][500];
bool used[30004][500];
int solve(int i, int j) {
  int jj = j - (d - 250);
  if (i >= 30001) return 0;
  if (used[i][jj]) return dp[i][jj];
  used[i][jj] = true;
  int res;
  if (j == 1) {
    res = g[i] + max(solve(i + j, j), solve(i + j + 1, j + 1));
  } else {
    res = g[i] + max(max(solve(i + j - 1, j - 1), solve(i + j, j)),
                     solve(i + j + 1, j + 1));
  }
  dp[i][jj] = res;
  return res;
}
int main() {
  int n, q, t, x, y, m, k, ans;
  cin >> n >> d;
  for (int i = 0; i < n; i++) {
    cin >> x;
    g[x]++;
  }
  cout << solve(d, d) << "\n";
  return 0;
}
