#include <bits/stdc++.h>
using namespace std;
template <typename T>
T next_int() {
  T x = 0, p = 1;
  char ch;
  do {
    ch = getchar();
  } while (ch <= ' ');
  if (ch == '-') {
    p = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + (ch - '0');
    ch = getchar();
  }
  return p * x;
}
string next_token() {
  char ch;
  string ans = "";
  do {
    ch = getchar();
  } while (ch <= ' ');
  while (ch > ' ') {
    ans += ch;
    ch = getchar();
  }
  return ans;
}
const long long INF = (long long)1e18;
const int INFINT = (int)1e9 + 227 + 1;
const int MAXN = (int)3e4 + 227 + 1;
const int MOD = (int)1e9 + 7;
const long double EPS = 1e-9;
long long bin_pow(long long a, long long b) {
  if (!b) return 1;
  long long ans = bin_pow(a, b / 2);
  ans = ans * ans % MOD;
  if (b % 2) ans = ans * a % MOD;
  return ans;
}
int dp[MAXN][700];
int a[MAXN];
int main() {
  int n, d;
  cin >> n >> d;
  for (int i = 0; i < n; i++) a[next_int<int>()]++;
  for (int i = 0; i <= 30000; i++)
    for (int j = 0; j < 700; j++) dp[i][j] = -INFINT;
  dp[d][350] = a[d];
  int ans = 0;
  for (int i = d; i <= 30000; i++) {
    for (int j = 0; j < 700; j++) {
      if (dp[i][j] == -INFINT) continue;
      int k = j - 350 + d;
      if (k <= 0) continue;
      ans = max(ans, dp[i][j]);
      if (i + k <= 30000) dp[i + k][j] = max(dp[i + k][j], dp[i][j] + a[i + k]);
      if (i + k - 1 <= 30000 && k)
        dp[i + k - 1][j - 1] =
            max(dp[i + k - 1][j - 1], dp[i][j] + a[i + k - 1]);
      if (i + k + 1 <= 30000 && j + 1 < 700)
        dp[i + k + 1][j + 1] =
            max(dp[i + k + 1][j + 1], dp[i][j] + a[i + k + 1]);
    }
  }
  cout << ans << "\n";
}
