#include <bits/stdc++.h>
using namespace std;
int main() {
  const int MAX = 30000;
  ios::sync_with_stdio(false);
  int n, d, maxg;
  cin >> n >> d;
  vector<int> g(MAX + 1);
  for (int i = 0; i < n; i++) {
    cin >> maxg;
    g[maxg]++;
  }
  vector<map<int, int>> dp(MAX + 1);
  dp[d][d] = g[d];
  int val = g[d];
  for (int i = d; i < maxg; i++) {
    if (dp[i].find(1) != dp[i].end() && dp[i][1] == val) dp[i] = {{1, val}};
    for (auto &p : dp[i]) {
      int maxj = min(maxg, i + p.first + 1);
      for (int j = i + max(p.first - 1, 1); j <= maxj; j++) {
        int &jv = dp[j][j - i];
        jv = max(jv, p.second + g[j]);
        val = max(val, jv);
      }
    }
  }
  cout << val << '\n';
}
