#include <bits/stdc++.h>
using namespace std;
const long long N = 3e4 + 1;
const long long L = 350;
long long mas[N];
long long dp[N][750];
int main() {
  long long n, l;
  cin >> n >> l;
  for (long long i = 0; i < n; ++i) {
    long long a;
    cin >> a;
    mas[a]++;
  }
  for (long long i = 0; i < N; ++i)
    for (long long j = 0; j < 750; ++j) dp[i][j] = -(long long)(1e9 + 7);
  long long offset = max(1LL, l - L);
  long long ans = 0;
  ans = dp[l][l - offset] = mas[l];
  for (long long i = l; i < N; ++i)
    for (long long len = max(1LL, l - L); len < min(N, l + L); ++len)
      if (dp[i][len - offset] != -(long long)(1e9 + 7)) {
        if (i + len < N)
          dp[i + len][len - offset] = max(dp[i + len][len - offset],
                                          dp[i][len - offset] + mas[i + len]);
        if (i + len + 1 < N)
          dp[i + len + 1][len + 1 - offset] =
              max(dp[i + len + 1][len + 1 - offset],
                  dp[i][len - offset] + mas[i + len + 1]);
        if (len - 1 && i + len - 1 < N)
          dp[i + len - 1][len - 1 - offset] =
              max(dp[i + len - 1][len - 1 - offset],
                  dp[i][len - offset] + mas[i + len - 1]);
        ans = max(ans, dp[i][len - offset]);
      }
  cout << ans << "\n";
  return 0;
}
