#include <bits/stdc++.h>
using namespace std;
long long n, d, dp[30005][600], tr[30005], x, ans;
bool b[30005][600];
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> d;
  for (int i = 0; i < n; i++) {
    cin >> x;
    tr[x]++;
  }
  b[d][300] = 1;
  dp[d][300] = tr[d];
  for (int i = d; i <= 30000; i++) {
    for (int j = 0; j < 600; j++) {
      if (!b[i][j]) continue;
      ans = max(ans, dp[i][j]);
      if (i + d + j - 300 <= 30000) {
        b[i + d + j - 300][j] = 1;
        dp[i + d + j - 300][j] =
            max(dp[i + d + j - 300][j], dp[i][j] + tr[i + d + j - 300]);
      }
      if (i + d + j - 300 + 1 <= 30000) {
        b[i + d + j - 300 + 1][j + 1] = 1;
        dp[i + d + j - 300 + 1][j + 1] = max(
            dp[i + d + j - 300 + 1][j + 1], dp[i][j] + tr[i + d + j - 300 + 1]);
      }
      if (i + d + j - 300 - 1 <= 30000) {
        b[i + d + j - 300 - 1][j - 1] = 1;
        dp[i + d + j - 300 - 1][j - 1] = max(
            dp[i + d + j - 300 - 1][j - 1], dp[i][j] + tr[i + d + j - 300 - 1]);
      }
    }
  }
  cout << ans << endl;
}
