#include <bits/stdc++.h>
using namespace std;
int _f[30001][1200] = {0};
int *f[30001];
int gem[30001] = {0};
int main() {
  int n, d;
  scanf("%d%d", &n, &d);
  while (n--) {
    int t;
    scanf("%d", &t);
    gem[t]++;
  }
  memset(_f, -1, sizeof(_f));
  for (int i = 0; i <= 30000; i++) f[i] = _f[i] + 600;
  f[d][0] = gem[0] + gem[d];
  int ans = 0;
  for (int i = 0; i <= 30000; i++) {
    for (int j = -500; j <= 500; j++) {
      if (f[i][j] > -1) {
        if (d + j > 1 && i + d + j - 1 <= 30000)
          f[i + d + j - 1][j - 1] =
              max(f[i + d + j - 1][j - 1], f[i][j] + gem[i + d + j - 1]);
        if (d + j > 0 && i + d + j <= 30000) {
          f[i + d + j][j] = max(f[i + d + j][j], f[i][j] + gem[i + d + j]);
        }
        if (d + j > 0 && i + d + j + 1 <= 30000) {
          f[i + d + j + 1][j + 1] =
              max(f[i + d + j + 1][j + 1], f[i][j] + gem[i + d + j + 1]);
        }
      }
      ans = max(ans, f[i][j]);
    }
  }
  printf("%d\n", ans);
  return 0;
}
