#include <bits/stdc++.h>
using namespace std;
long n, d;
long a[32768][1024];
long v[32768];
int main() {
  scanf("%ld %ld", &n, &d);
  memset(v, 0, sizeof(v));
  memset(a, 0XFE, sizeof(a));
  for (long f = 0; f < n; ++f) {
    long t;
    scanf("%ld", &t);
    ++v[t];
  }
  long ans = a[d][512] = 0;
  for (long f = d; f < 32768; ++f) {
    long dt = long(ceil(sqrt(2 * (f - d))));
    for (long j = max(d - dt, long(1)); j <= d + dt; ++j) {
      long k = j - d + 512;
      if (a[f][k] < 0) continue;
      a[f][k] += v[f];
      ans = max(a[f][k], ans);
      if (f + j > 32768) continue;
      if (j != 1) a[f + j - 1][k - 1] = max(a[f + j - 1][k - 1], a[f][k]);
      if (f + j >= 32768) continue;
      a[f + j][k] = max(a[f + j][k], a[f][k]);
      if (f + j + 1 >= 32768) continue;
      a[f + j + 1][k + 1] = max(a[f + j + 1][k + 1], a[f][k]);
    }
  }
  printf("%ld", ans);
  return 0;
}
