#include <bits/stdc++.h>
using namespace std;
int sum[30005], f[30005][805];
int main(void) {
  int i, j, k, n, m, x, len, ans = 0;
  scanf("%d%d", &n, &m);
  for (i = 1; i <= n; ++i) {
    scanf("%d", &x);
    ++sum[x];
  }
  for (i = 0; i <= 30002; ++i) {
    for (j = -400; j <= 400; ++j) f[i][j + 400] = -0x3F3F3F3F;
  }
  f[m][400] = sum[0] + sum[m];
  for (i = m; i <= 30002; ++i) {
    for (j = -400; j <= 400; ++j) {
      if (f[i][j + 400] == -0x3F3F3F3F) continue;
      for (k = -1; k <= 1; ++k) {
        len = j + m + k;
        if (j + k < -400 || j + k > 400 || len < 1 || i + len > 30002) continue;
        f[i + len][j + k + 400] =
            max(f[i + len][j + k + 400], f[i][j + 400] + sum[i + len]);
      }
    }
  }
  for (i = 1; i <= 30002; ++i) {
    for (j = -400; j <= 400; ++j) ans = max(ans, f[i][j + 400]);
  }
  printf("%d\n", ans);
  return 0;
}
