#include <bits/stdc++.h>
using namespace std;
int a[30005], f[30005][500 + 5];
int main() {
  int n, d, i, j;
  scanf("%d%d", &n, &d);
  memset(a, 0, sizeof(a));
  for (i = 1; i <= n; i++) {
    int x;
    scanf("%d", &x);
    a[x]++;
  }
  memset(f, -1, sizeof(f));
  f[d][500 / 2] = a[d];
  int ans = 0;
  for (i = d; i <= 30000; i++) {
    for (j = 0; j <= 500; j++) {
      if (f[i][j] != -1) {
        ans = max(f[i][j], ans);
        if (i + d + j - 500 / 2 <= 30000)
          f[i + d + j - 500 / 2][j] =
              max(f[i + d + j - 500 / 2][j], f[i][j] + a[i + d + j - 500 / 2]);
        if (i + d + j - 500 / 2 - 1 <= 30000 && d + j - 500 / 2 - 1)
          f[i + d + j - 500 / 2 - 1][j - 1] =
              max(f[i + d + j - 500 / 2 - 1][j - 1],
                  f[i][j] + a[i + d + j - 500 / 2 - 1]);
        if (i + d + j - 500 / 2 + 1 <= 30000)
          f[i + d + j + 1 - 500 / 2][j + 1] =
              max(f[i + d + j + 1 - 500 / 2][j + 1],
                  f[i][j] + a[i + d + j + 1 - 500 / 2]);
      }
    }
  }
  printf("%d\n", ans);
  return 0;
}
