#include <bits/stdc++.h>
using namespace std;
const int MAXN = 30100;
const int LEN = 30000;
const int MAXK = 265;
int n, d;
int ok[MAXN];
int to_true(int v) { return v + (d - MAXK + 5); }
int to_false(int v) { return v - (d - MAXK + 5); }
int memo[MAXN][2 * MAXK + 150];
int dp(int pos, int last) {
  if (pos >= LEN) {
    return 0;
  }
  assert(to_false(last) >= 0 && to_false(last) < 2 * MAXK);
  int &ret = memo[pos][to_false(last)];
  if (ret != -1) {
    return ret;
  }
  ret = 0;
  for (int df = -1; df <= 1; df++) {
    int njump = last + df;
    if (njump < 1) continue;
    if (pos + njump >= MAXN) continue;
    ret = max(ret, dp(pos + njump, njump) + ok[pos + njump]);
  }
  return ret;
}
int main() {
  while (scanf("%d%d", &n, &d) >= 1) {
    memset(ok, 0, sizeof ok);
    for (int i = (0); i < (int)(n); i++) {
      int tmp;
      scanf("%d", &tmp);
      ok[tmp]++;
    }
    memset(memo, -1, sizeof memo);
    printf("%d\n", dp(d, d) + ok[d]);
  }
  return 0;
}
