#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline T abs(T a) {
  return ((a < 0) ? -a : a);
}
template <typename T>
inline T sqr(T a) {
  return a * a;
}
const int N = 30009;
const int MOD = 1e9 + 7;
const int INF = 1e9;
const long long INF64 = 2e18;
const long double PI = 3.1415926535897932384626433832795;
const long double eps = 1e-9;
int a[N];
int dp[N][1009];
int main() {
  srand(time(NULL));
  cout << setprecision(10) << fixed;
  cerr << setprecision(10) << fixed;
  int n, d;
  cin >> n >> d;
  for (int i = 0; i < (int)(n); ++i) {
    int x;
    cin >> x;
    ++a[x];
  }
  for (int i = 0; i < (int)(N); ++i)
    for (int j = 0; j < (int)(1009); ++j) dp[i][j] = -INF;
  dp[d][500] = a[d];
  for (int i = 0; i < (int)(N); ++i) {
    for (int j = 0; j < (int)(1009); ++j) {
      if (i == 10 && j == 500) int xx = 0;
      int len = d + j - 500;
      if (len >= 1 && i + len < N && j < 1009 && j >= 0)
        dp[i + len][j] = max(dp[i + len][j], dp[i][j] + a[i + len]);
      --len;
      if (len >= 1 && i + len < N && j - 1 < 1009 && j - 1 >= 0)
        dp[i + len][j - 1] = max(dp[i + len][j - 1], dp[i][j] + a[i + len]);
      len += 2;
      if (len >= 1 && i + len < N && j + 1 < 1009 && j + 1 >= 0)
        dp[i + len][j + 1] = max(dp[i + len][j + 1], dp[i][j] + a[i + len]);
    }
  }
  int mx = 0;
  for (int i = 0; i < (int)(N); ++i)
    for (int j = 0; j < (int)(1009); ++j) mx = max(mx, dp[i][j]);
  cout << mx;
  return 0;
}
