#include <bits/stdc++.h>
int n, d, M, G[30001];
int dt[30001][500], used[30001][500];
int solve(int v, int p) {
  if (p <= 0) return -987654321;
  if (v > M) return 0;
  int pre = p - (d - 250);
  if (used[v][pre] == 0) {
    used[v][pre] = 1;
    dt[v][pre] = std::max(solve(v + p - 1, p - 1),
                          std::max(solve(v + p, p), solve(v + p + 1, p + 1))) +
                 G[v];
  }
  return dt[v][pre];
}
int main() {
  scanf("%d%d", &n, &d);
  for (int i = 0; i < n; i++) {
    int t;
    scanf("%d", &t);
    M = std::max(M, t);
    G[t]++;
  }
  printf("%d\n", solve(d, d));
}
