#include <bits/stdc++.h>
using namespace std;
template <class T>
int getbit(T s, int i) {
  return (s >> i) & 1;
}
template <class T>
T onbit(T s, int i) {
  return s | (T(1) << i);
}
template <class T>
T offbit(T s, int i) {
  return s & (~(T(1) << i));
}
template <class T>
int cntbit(T s) {
  return __builtin_popcount(s);
}
template <class T>
inline T gcd(T a, T b) {
  T r;
  while (b != 0) {
    r = a % b;
    a = b;
    b = r;
  }
  return a;
}
const int maxn = 30000, N = 250;
long long n, d, dp[maxn + 10][2 * N + 10], ok[maxn + 10], res;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> d;
  for (long long i = 1, _b = n; i <= _b; i++) {
    long long x;
    cin >> x;
    ok[x]++;
  }
  memset(dp, -1, sizeof dp);
  dp[d][N] = 0;
  for (long long i = 1, _b = maxn; i <= _b; i++) {
    for (long long j = 0, _b = 2 * N; j <= _b; j++) {
      long long nhay = d + j - N;
      if (nhay <= 0 || dp[i][j] == -1) continue;
      dp[i][j] += ok[i];
      res = max(res, dp[i][j]);
      if (i + nhay <= maxn) dp[i + nhay][j] = max(dp[i + nhay][j], dp[i][j]);
      if (i + nhay + 1 <= maxn)
        dp[i + nhay + 1][j + 1] = max(dp[i + nhay + 1][j + 1], dp[i][j]);
      if (i + nhay - 1 <= maxn && nhay > 1)
        dp[i + nhay - 1][j - 1] = max(dp[i + nhay - 1][j - 1], dp[i][j]);
    }
  }
  cout << res << "\n";
  return 0;
}
