#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e4 + 4;
int dp[maxn][500];
int t[maxn];
int n, d, pos;
int main() {
  ios::sync_with_stdio(false);
  memset(dp, -1, sizeof dp);
  memset(t, 0, sizeof t);
  cin >> n >> d;
  int i, j, k;
  for (i = 1; i <= n; ++i) {
    cin >> pos;
    t[pos]++;
  }
  dp[d][250] = t[d];
  int ans = t[d];
  int s = max(1, 251 - d);
  for (i = d + 1; i <= 30000; ++i)
    for (j = s; j < 499; ++j) {
      int dis = d - 250 + j;
      if (dis > i) continue;
      if (dis == 1) {
        if (dp[i - 1][j] == -1 && dp[i - 1][j + 1] == -1) continue;
        dp[i][j] = max(dp[i - 1][j], dp[i - 1][j + 1]) + t[i];
      } else {
        if (dp[i - dis][j - 1] != -1 || dp[i - dis][j] != -1)
          dp[i][j] = max(dp[i - dis][j], dp[i - dis][j - 1]);
        if (dp[i - dis][j + 1] != -1)
          dp[i][j] = max(dp[i][j], dp[i - dis][j + 1]);
        if (dp[i][j] != -1) dp[i][j] += t[i];
      }
      ans = max(ans, dp[i][j]);
    }
  cout << ans << endl;
  return 0;
}
