#include <bits/stdc++.h>
using namespace std;
int N, d, ans, m, A[30005], f[30005][505];
inline int IN() {
  char c;
  register int first = 0;
  while ((c = getchar()) < 48 && c ^ '-' || c > 57)
    ;
  bool f = c == '-';
  if (f) (c = getchar());
  for (; c > 47 && c < 58; (c = getchar())) first = first * 10 + c - 48;
  if (f) first = -first;
  return first;
}
inline void ck(int &first, int second) {
  if (second > first) first = second;
}
int main() {
  N = IN();
  d = IN();
  for (int _r = N, i = 1; i <= _r; ++i) {
    int first = IN();
    ++A[first];
    if (first > m) m = first;
  }
  memset(f, 0x80, sizeof f);
  f[d][250] = A[d];
  for (int _r = m, i = d; i < _r; ++i) {
    for (int _r = 500, j = 0; j <= _r; ++j)
      if (f[i][j] >= 0) {
        int L = j + d - 250;
        if (L > 0 && i + L <= m) ck(f[i + L][j], f[i][j] + A[i + L]);
        --L;
        if (L > 0 && i + L <= m) ck(f[i + L][j - 1], f[i][j] + A[i + L]);
        L += 2;
        if (L > 0 && i + L <= m) ck(f[i + L][j + 1], f[i][j] + A[i + L]);
      }
  }
  for (int _r = m, i = d; i <= _r; ++i)
    for (int _r = 500, j = 0; j <= _r; ++j) ck(ans, f[i][j]);
  printf("%d\n", ans);
}
