#include <bits/stdc++.h>
using namespace std;
int n;
int d;
int p[30010];
int f[30010][610];
int find(int x, int y) {
  if (x > 30000) return 0;
  int z = y - d + 300;
  if (f[x][z] != -1) return f[x][z];
  int v = max(find(x + y, y), find(x + y + 1, y + 1));
  if (y > 1) v = max(v, find(x + y - 1, y - 1));
  return f[x][z] = p[x] + v;
}
int main(int argc, char* argv[]) {
  scanf("%d%d", &n, &d);
  int x;
  for (int i = 1; i <= n; i++) scanf("%d", &x), p[x] += 1;
  memset(f, -1, sizeof(f));
  printf("%d\n", find(d, d));
  return 0;
}
