#include <bits/stdc++.h>
using namespace std;
const int oo = 0x3f3f3f3f;
const int maxn = 30000;
const int max0 = 1000;
int n, d;
int a[maxn + 5];
int dp[maxn + 5][max0 + 5];
int ans = 0;
template <typename T>
bool chkmax(T &a, const T &b) {
  return a < b ? a = b, 1 : 0;
}
template <typename T>
bool chkmin(T &a, const T &b) {
  return a > b ? a = b, 1 : 0;
}
int main() {
  scanf("%d%d", &n, &d);
  for (int i = (0), _end_ = (n); i < _end_; ++i) {
    static int first;
    scanf("%d", &first);
    ++a[first - d];
  }
  memset(dp, -oo, sizeof dp);
  dp[0][max0 >> 1] = a[0];
  ans = a[0];
  for (int i = (0), _end_ = (maxn); i < _end_; ++i) {
    for (int j = (0), _end_ = (max0); j < _end_; ++j) {
      int dis = d + j - (max0 >> 1);
      if (dp[i][j] >= 0) {
        chkmax(ans, dp[i][j]);
        if (i + dis - 1 < maxn && j >= 0)
          chkmax(dp[i + dis - 1][j - 1], dp[i][j] + a[i + dis - 1]);
        if (i + dis < maxn) chkmax(dp[i + dis][j], dp[i][j] + a[i + dis]);
        if (i + dis + 1 < maxn)
          chkmax(dp[i + dis + 1][j + 1], dp[i][j] + a[i + dis + 1]);
      }
    }
  }
  printf("%d\n", ans);
  return 0;
}
