#include <bits/stdc++.h>
#pragma comment(linker, ”/ STACK : 801000“)
using namespace std;
long long dp[30010][610], d, gem[30010];
long long rec(long long pos, long long laf) {
  if (laf <= 0) return 0LL;
  if (pos > 30000) return 0LL;
  long long &ret = dp[pos][d - laf + 300];
  if (ret != -1) return ret;
  ret = 0LL;
  ret = gem[pos] + max(max(rec(pos + laf - 1, laf - 1), rec(pos + laf, laf)),
                       rec(pos + laf + 1, laf + 1));
  return ret;
}
int main() {
  long long n, i, in;
  scanf(" %I64d %I64d", &n, &d);
  for (i = 0LL; i < n; i++) {
    scanf(" %d", &in);
    gem[in]++;
  }
  memset(dp, -1, sizeof(dp));
  printf("%I64d\n", rec(d, d));
  return 0;
}
