#include <bits/stdc++.h>
using namespace std;
vector<long long> ilha(30001, 0);
long long dp[30001][500];
bool used[30001][500] = {0};
long long ans = 0;
long long d;
int solve(int i, int j) {
  if (i > 30000 || j < (d - 250) || j >= (d + 250) || j <= 0) return 0;
  int jj = (j - d) + 250;
  if (used[i][jj]) return dp[i][jj];
  long long cur = ilha[i];
  used[i][jj] = true;
  long long a[3] = {
      solve(i + j - 1, j - 1),
      solve(i + j, j),
      solve(i + j + 1, j + 1),
  };
  dp[i][jj] = max({a[0], a[1], a[2]}) + cur;
  return dp[i][jj];
}
int main() {
  std::ios::sync_with_stdio(false);
  long long n;
  cin >> n >> d;
  for (__typeof(n) i = (0) - ((0) > (n)); i != (n) - ((0) > (n));
       i += 1 - 2 * ((0) > (n))) {
    long long a;
    cin >> a;
    ilha[a]++;
  }
  cout << solve(d, d) << "\n";
}
