#include <bits/stdc++.h>
using namespace std;
int dp[30010];
int memo[30001][600];
int n, d;
int solve(int i, int j) {
  int jj = j - (d - 250);
  if (i >= 30001) return 0;
  if (memo[i][jj] != -1) return memo[i][jj];
  int ans;
  if (j == 1) {
    ans = dp[i] + max(solve(i + j, j), solve(i + j + 1, j + 1));
  } else {
    ans = dp[i] + max(max(solve(i + j, j), solve(i + j + 1, j + 1)),
                      solve(i + j - 1, j - 1));
  }
  memo[i][jj] = ans;
  return ans;
}
int main(int argc, char* argv[]) {
  cin >> n >> d;
  memset((dp), (0), sizeof((dp)));
  memset((memo), (-1), sizeof((memo)));
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    dp[x]++;
  }
  cout << solve(d, d) << endl;
  return 0;
}
