#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > dp[60100];
int d, n, a[60100], ans;
int main() {
  cin >> n >> d;
  for (int i = 1; i <= n; i++) {
    int x;
    cin >> x;
    a[x]++;
  }
  dp[d].push_back(make_pair(d, a[d]));
  for (int i = 1; i <= 30000; i++) {
    sort(dp[i].begin(), dp[i].end());
    for (int j = 0; j < dp[i].size(); j++) {
      int k = j;
      while (k < dp[i].size() && dp[i][j].first == dp[i][k].first) k++;
      k--;
      ans = max(ans, dp[i][k].second);
      if (dp[i][k].first <= 2) {
        dp[i + 1].push_back(make_pair(1, dp[i][k].second + a[i + 1]));
      } else {
        for (int z = dp[i][k].first - 1; z <= dp[i][k].first + 1; z++) {
          int to = i + z;
          if (to <= 30000)
            dp[to].push_back(make_pair(z, dp[i][k].second + a[to]));
        }
      }
      j = k;
    }
  }
  cout << ans << endl;
  return 0;
}
