#include <bits/stdc++.h>
using namespace std;
void Fast() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
}
void File() {}
long long gcd(long long a, long long b) { return !b ? a : gcd(b, a % b); }
int dp[30001][500];
int gem[30001], n, d;
int mx = 0;
int solve(int island = d, int res = 250) {
  int& ans = dp[island][res];
  if (~ans) return ans;
  ans = gem[island];
  int x = d + (res - 250);
  if (island + x - 1 > island && island + x - 1 <= mx)
    ans = max(ans, solve(island + x - 1, res - 1) + gem[island]);
  if (island + x > island && island + x <= mx)
    ans = max(ans, solve(island + x, res) + gem[island]);
  if (island + x + 1 > island && island + x + 1 <= mx)
    ans = max(ans, solve(island + x + 1, res + 1) + gem[island]);
  return ans;
}
int main() {
  File(), Fast();
  memset(dp, -1, sizeof(dp));
  cin >> n >> d;
  while (n--) {
    int x;
    cin >> x;
    mx = max(mx, x);
    gem[x]++;
  }
  cout << solve() + gem[0] << "\n";
}
