#include <bits/stdc++.h>
using namespace std;
int maxi = 0;
int p[30005];
int f[30005];
int n, d;
int dp[30005][505], done[30005][505];
int solve(int curr, int l) {
  int re = l - (d - 250);
  if (curr > maxi) {
    return 0;
  }
  if (done[curr][re] == 1) return dp[curr][re];
  int ans = 0;
  if (l > 1) {
    ans = max(ans, solve(curr + l - 1, l - 1)) + f[curr];
  }
  ans = max(ans, solve(curr + l, l) + f[curr]);
  ans = max(ans, solve(curr + l + 1, l + 1) + f[curr]);
  dp[curr][re] = ans;
  done[curr][re] = 1;
  return ans;
}
int main() {
  cin >> n >> d;
  for (int i = 1; i <= n; i++) {
    cin >> p[i];
    maxi = max(maxi, p[i]);
    f[p[i]]++;
  }
  cout << solve(d, d) << endl;
}
