#include <bits/stdc++.h>
using namespace std;
int max(int a, int b) { return a > b ? a : b; }
vector<int> vec(30001, 0);
int dp[30001][500] = {};
bool used[30001][500] = {};
int d;
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 = vec[i] + max(solve(i + j + 1, j + 1), solve(i + j, j));
  else
    res = vec[i] + max(solve(i + j + 1, j + 1),
                       max(solve(i + j - 1, j - 1), solve(i + j, j)));
  dp[i][jj] = res;
  return res;
}
int main() {
  int n;
  cin >> n >> d;
  int val;
  int max_sum;
  for (int i = 0; i < n; i++) {
    cin >> val;
    vec[val]++;
  }
  cout << solve(d, d);
  return 0;
}
