#include <bits/stdc++.h>
using namespace std;
const int nax = 30001;
long long dp[nax][600], gems[nax];
int d, OFFSET;
long long rec(int pos, int jmp) {
  if (pos >= nax || jmp <= 0) return 0;
  long long &ans = dp[pos][jmp - OFFSET];
  if (ans != -1) return ans;
  return ans =
             gems[pos] + max({rec(pos + jmp + 1, jmp + 1), rec(pos + jmp, jmp),
                              rec(pos + jmp - 1, jmp - 1)});
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  memset(gems, 0, sizeof gems);
  int n, p;
  cin >> n >> d;
  OFFSET = max(0, d - 250);
  for (int i = 0; i < int(n); i++) cin >> p, gems[p]++;
  memset(dp, -1, sizeof dp);
  cout << rec(d, d) << "\n";
}
