#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long ll;
const int M = 30001;
int dp[M][250*2];
bool used[M][250*2] = {};
int d;
int gem[M] = {};
int solve(int i, int j) {
int jj = j-(d-250);
if (i >= M) return 0;
if (used[i][jj]) return dp[i][jj];
used[i][jj] = true;
int res;
if (j == 1) {
res = gem[i] + max(solve(i+j, j), solve(i+j+1, j+1));
} else {
res = gem[i] + max(max(solve(i+j-1, j-1), solve(i+j, j)), solve(i+j+1, j+1));
}
dp[i][jj] = res;
return res;
}
int main() {
int n;
scanf("%d %d", &n, &d);
for (int i = 0; i < n; i++) {
int x;
scanf("%d", &x);
gem[x]++;
}
printf("%d\n", solve(d, d));
return 0;
}
I2luY2x1ZGUgPGNzdGRpbz4KI2luY2x1ZGUgPGFsZ29yaXRobT4KCnVzaW5nIG5hbWVzcGFjZSBzdGQ7Cgp0eXBlZGVmIGxvbmcgbG9uZyBsbDsKCmNvbnN0IGludCBNID0gMzAwMDE7CgppbnQgZHBbTV1bMjUwKjJdOwpib29sIHVzZWRbTV1bMjUwKjJdID0ge307CgppbnQgZDsKaW50IGdlbVtNXSA9IHt9OwoKaW50IHNvbHZlKGludCBpLCBpbnQgaikgewogICAgaW50IGpqID0gai0oZC0yNTApOwogICAgaWYgKGkgPj0gTSkgcmV0dXJuIDA7CiAgICBpZiAodXNlZFtpXVtqal0pIHJldHVybiBkcFtpXVtqal07CiAgICB1c2VkW2ldW2pqXSA9IHRydWU7CiAgICBpbnQgcmVzOwogICAgaWYgKGogPT0gMSkgewogICAgICAgIHJlcyA9IGdlbVtpXSArIG1heChzb2x2ZShpK2osIGopLCBzb2x2ZShpK2orMSwgaisxKSk7CiAgICB9IGVsc2UgewogICAgICAgIHJlcyA9IGdlbVtpXSArIG1heChtYXgoc29sdmUoaStqLTEsIGotMSksIHNvbHZlKGkraiwgaikpLCBzb2x2ZShpK2orMSwgaisxKSk7CiAgICB9CiAgICBkcFtpXVtqal0gPSByZXM7CiAgICByZXR1cm4gcmVzOwp9CgppbnQgbWFpbigpIHsKICAgIGludCBuOwogICAgc2NhbmYoIiVkICVkIiwgJm4sICZkKTsKICAgIGZvciAoaW50IGkgPSAwOyBpIDwgbjsgaSsrKSB7CiAgICAgICAgaW50IHg7CiAgICAgICAgc2NhbmYoIiVkIiwgJngpOwogICAgICAgIGdlbVt4XSsrOwogICAgfQogICAgcHJpbnRmKCIlZFxuIiwgc29sdmUoZCwgZCkpOwogICAgcmV0dXJuIDA7Cn0=