#include <bits/stdc++.h>
using namespace std;
int n, d, ul, ll, s, no;
vector<vector<int>> dp;
vector<int> frq(30001);
int solve(int pos, int l) {
  if (pos > 30000 || l <= 0) return 0;
  if (dp[pos][l - ll] != -1) return dp[pos][l - ll];
  return dp[pos][l - ll] =
             frq[pos] + max({solve(pos + l, l), solve(pos + l + 1, l + 1),
                             solve(pos + l - 1, l - 1)});
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> d;
  for (s = 0, ul = d; s <= 30000; ++ul) s += ul;
  for (s = 0, ll = d; s <= 30000 && ll > 1; --ll) s += ll;
  dp = vector<vector<int>>(30001, vector<int>(ul - ll + 2, -1));
  for (int i = 0; i < n; ++i) {
    cin >> no;
    ++frq[no];
  }
  cout << solve(d, d);
}
