#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:100000000")
using namespace std;
const long double pi = acos(-1.0);
const int N = 30001;
const int D = 500;
int ans[N][2 * D], cnt[N], best, n, d, x;
void relax(int& a, int b) {
  if (a < b) a = b;
}
int main() {
  scanf("%d%d", &n, &d);
  for (int i = 0; i < n; ++i) scanf("%d", &x), cnt[x]++;
  for (int i = 0; i < N; ++i)
    for (int j = 0; j < 2 * D; ++j) ans[i][j] = -1;
  ans[d][D] = cnt[d];
  for (int i = 0; i < N; ++i)
    for (int j = 0; j < 2 * D; ++j) {
      if (ans[i][j] == -1) continue;
      relax(best, ans[i][j]);
      for (int delta = -1; delta <= 1; ++delta) {
        int jump = d + j - D + delta;
        if ((jump > 0) && (i + jump < N) && (jump - d + D >= 0) &&
            (jump - d + D < 2 * D))
          relax(ans[i + jump][jump - d + D], ans[i][j] + cnt[i + jump]);
      }
    }
  printf("%d\n", best);
  return 0;
}
