#include <bits/stdc++.h>
using namespace std;
vector<int> cnt(30001, 0);
int bf(int i, int d) {
  if (i > 30000) return 0;
  return cnt[i] +
         max({bf(i + d - 1, d - 1), bf(i + d, d), bf(i + d + 1, d + 1)});
}
int main() {
  int n, d, ans = 0;
  cin >> n >> d;
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    ++cnt[x];
  }
  if (d > 2000) return cout << bf(d, d), 0;
  vector<vector<int>> dp(30001, vector<int>(2100, -30000));
  dp[d][d] = cnt[d];
  for (int i = d + 1; i < 30001; ++i)
    for (int j = 1; j < 2050; ++j) {
      if (i - j > 0)
        dp[i][j] =
            max({dp[i - j][j - 1], dp[i - j][j], dp[i - j][j + 1]}) + cnt[i];
      ans = max(ans, dp[i][j]);
    }
  cout << ans;
}
