#include <bits/stdc++.h>
int max(int a, int b) { return a > b ? a : b; }
int h[30001], dp[70000][503];
int main() {
  int n, m, d, i, j;
  scanf("%d%d", &n, &d);
  for (i = 1; i <= n; ++i) {
    scanf("%d", &m);
    ++h[m];
  }
  for (i = 30000; i >= d; --i) {
    for (j = -249; j < 250; ++j) {
      if (d + j > 1)
        dp[i][250 + j] =
            h[i] + max(dp[i + d + j][250 + j], max(dp[i + d + j - 1][249 + j],
                                                   dp[i + d + j + 1][251 + j]));
      if (d + j == 1)
        dp[i][250 + j] =
            h[i] + max(dp[i + d + j][250 + j], dp[i + d + j + 1][251 + j]);
    }
  }
  printf("%d", dp[d][250]);
  return 0;
}
