#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > dp[600001];
int islands[600001];
int ans = 0;
int main() {
  int n, d;
  cin >> n >> d;
  int MX = d;
  int k;
  for (int i = 1; i <= n; ++i) {
    cin >> k;
    islands[k]++;
    MX = max(MX, k);
  }
  dp[d].push_back(make_pair(d, 0));
  for (int i = d; i <= MX; ++i) {
    sort(dp[i].begin(), dp[i].end());
    reverse(dp[i].begin(), dp[i].end());
    for (int j = 0; j < dp[i].size(); ++j) {
      if (j > 0 && dp[i][j].first == dp[i][j - 1].first) continue;
      pair<int, int> p = dp[i][j];
      int l = dp[i][j].first;
      int gems = dp[i][j].second;
      if (l - 1 > 0) {
        dp[i + l - 1].push_back(make_pair(l - 1, gems + islands[i]));
      }
      dp[i + l].push_back(make_pair(l, gems + islands[i]));
      dp[i + l + 1].push_back(make_pair(l + 1, gems + islands[i]));
      ans = max(ans, gems + islands[i]);
    }
  }
  cout << ans << endl;
  return 0;
}
