#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T>
using V = vector<T>;
template <class T, class U>
using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
constexpr ll MOD = 1000000007;
constexpr ll HIGHINF = (ll)1e18;
constexpr int INF = 1e9;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, d;
  cin >> n >> d;
  V<int> tre(30001, 0);
  for (int i = 0; i < n; i++) {
    int c;
    cin >> c;
    tre[c]++;
  }
  V<V<int> > dp(30001, V<int>(1000, -1));
  dp[d][500] = tre[d];
  int offset = 500;
  for (int i = d; i < 30000; i++) {
    for (int j = -500; j < 500; j++) {
      if (dp[i][j + offset] < 0) continue;
      if (i < i + d + j - 1 and i + d + j - 1 <= 30000)
        chmax(dp[i + d + j - 1][j - 1 + offset],
              dp[i][j + offset] + tre[i + d + j - 1]);
      if (i < i + d + j and i + d + j <= 30000)
        chmax(dp[i + d + j][j + offset], dp[i][j + offset] + tre[i + d + j]);
      if (i < i + d + j + 1 and i + d + j + 1 <= 30000)
        chmax(dp[i + d + j + 1][j + 1 + offset],
              dp[i][j + offset] + tre[i + d + j + 1]);
    }
  }
  int ans = 0;
  for (int i = 1; i <= 30000; i++) {
    for (int j = 0; j < 1000; j++) chmax(ans, dp[i][j]);
  }
  cout << ans << '\n';
  return 0;
}
