#include <bits/stdc++.h>
using namespace std;
const int MAX_ISLAND = 30000;
const int X = 250;
int n, d, p[MAX_ISLAND + 10], hasGem[MAX_ISLAND + 10];
int pos[MAX_ISLAND + 10][2 * X + 10], dp[MAX_ISLAND + 10][2 * X + 10];
int main() {
  ios::sync_with_stdio(0);
  cin >> n >> d;
  for (int i = 1; i <= n; i++) {
    cin >> p[i];
    hasGem[p[i]]++;
  }
  int l = max(1, d - X), r = min(d + X, MAX_ISLAND), ans = hasGem[d];
  pos[d][d - l + 1] = 1, dp[d][d - l + 1] = hasGem[d];
  for (int i = d + 1; i <= MAX_ISLAND; i++) {
    int extra = hasGem[i];
    for (int j = l; j <= r; j++)
      if (i > j) {
        if (j > l && pos[i - j][j - l])
          dp[i][j - l + 1] = max(dp[i][j - l + 1], dp[i - j][j - l] + extra),
                        pos[i][j - l + 1] = 1;
        if (pos[i - j][j - l + 1])
          dp[i][j - l + 1] =
              max(dp[i][j - l + 1], dp[i - j][j - l + 1] + extra),
                        pos[i][j - l + 1] = 1;
        if (j < r && pos[i - j][j - l + 2])
          dp[i][j - l + 1] =
              max(dp[i][j - l + 1], dp[i - j][j - l + 2] + extra),
                        pos[i][j - l + 1] = 1;
        if (pos[i][j - l + 1]) ans = max(ans, dp[i][j - l + 1]);
      }
  }
  cout << ans;
  return 0;
}
