#include <bits/stdc++.h>
using namespace std;
const int maxn = 30005;
const int off = 400;
int dp[maxn][800];
int v[maxn], n, d, maxd;
int main() {
  cin >> n >> d;
  for (int i = 1; i <= n; ++i) {
    int x;
    cin >> x;
    v[x]++;
    maxd = max(maxd, x);
  }
  memset(dp, -1, sizeof(dp));
  dp[d][off + d - d] = v[d] + v[0];
  int ans = dp[d][off];
  for (int i = d + 1; i <= maxd; ++i) {
    for (int k = -off; k <= off; ++k) {
      int rec = -1;
      int p = k + d;
      if (p <= 0 || p > i) continue;
      for (int dx = -1; dx <= 1; ++dx) {
        int st = p + dx;
        if (st <= 0 || st > (i - p)) continue;
        rec = max(dp[i - p][off + st - d], rec);
      }
      if (rec == -1) continue;
      dp[i][off + k] = rec + v[i];
      ans = max(ans, dp[i][off + k]);
    }
  }
  cout << ans;
  return 0;
}
