#include <bits/stdc++.h>
using namespace std;
const int maxN = 30 * 1000 + 5;
const int mod = 1000 * 1000 * 1000 + 7;
int dp[maxN][1020];
int cn[maxN];
int f(int t) { return t + 503; }
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, d;
  cin >> n >> d;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    cn[x]++;
  }
  dp[d][f(0)] = 1 + cn[d];
  for (int i = d; i < maxN; i++) {
    for (int j = -500; j <= 500; j++)
      if (dp[i][f(j)]) {
        int x = i + d;
        if (x + j < maxN)
          dp[x + j + 0][f(j + 0)] =
              max(dp[x + j + 0][f(j + 0)], dp[i][f(j)] + cn[x + j + 0]);
        if (x + j + 1 < maxN)
          dp[x + j + 1][f(j + 1)] =
              max(dp[x + j + 1][f(j + 1)], dp[i][f(j)] + cn[x + j + 1]);
        if (x + j - 1 < maxN && d + j - 1 > 0)
          dp[x + j - 1][f(j - 1)] =
              max(dp[x + j - 1][f(j - 1)], dp[i][f(j)] + cn[x + j - 1]);
      }
  }
  int maxi = 0;
  for (int i = 0; i < maxN; i++)
    for (int j = 0; j < 1020; j++) maxi = max(maxi, dp[i][j]);
  cout << maxi - 1 << endl;
  return 0;
}
