#include <bits/stdc++.h>
using namespace std;
int a[30003] = {0};
int dp[30005][950];
int n, d;
int func(int curr, int l) {
  if (dp[curr][(360 + l - d)] != -1) {
    return dp[curr][(360 + l - d)];
  }
  int tmp = 0, tmp1 = 0, tmp2 = 0, tmp3 = 0;
  if (curr + l - 1 < 30001 && l > 1) tmp = func(curr + l - 1, l - 1);
  if (curr + l < 30001) tmp1 = func(curr + l, l);
  if (curr + l + 1 < 30001) tmp2 = func(curr + l + 1, l + 1);
  tmp3 = max(max(tmp1, tmp2), tmp);
  return dp[curr][(360 + l - d)] = tmp3 + a[curr];
}
int main() {
  int tmp;
  scanf("%d%d", &n, &d);
  for (int i = 0; i < n; i++) {
    scanf("%d", &tmp);
    a[tmp]++;
  }
  memset(dp, -1, sizeof(dp));
  int ans = func(d, d);
  cout << ans;
  return 0;
}
