#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7, INF = 1e18;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t = 1;
  while (t--) {
    int n, d;
    cin >> n >> d;
    vector<int> p(30010, 0);
    for (int i = 0; i < n; i++) {
      int u;
      cin >> u;
      p[u]++;
    }
    vector<vector<int> > dp(30010, vector<int>(500, -1));
    dp[d][250] = p[d];
    for (int i = d; i <= 30000; i++) {
      for (int j = 0; j < 500; j++)
        if (dp[i][j] != -1) {
          int temp = j + d - 250;
          if (temp > 1 && i + temp - 1 <= 30000) {
            dp[i + temp - 1][j - 1] =
                max(dp[i + temp - 1][j - 1], p[i + temp - 1] + dp[i][j]);
          }
          if (i + temp <= 30000) {
            dp[i + temp][j] = max(dp[i + temp][j], p[i + temp] + dp[i][j]);
            dp[i + temp + 1][j + 1] =
                max(dp[i + temp + 1][j + 1], p[i + temp + 1] + dp[i][j]);
          }
        }
    }
    int ans = 0;
    for (int i = d; i <= 30000; i++) {
      for (int j = 0; j < 500; j++) {
        ans = max(ans, dp[i][j]);
      }
    }
    cout << ans << "\n";
  }
  return 0;
}
