#include <bits/stdc++.h>
using namespace std;
int n, m, ans, x, f = 320, a[30001], dp[30001][641];
inline long long read() {
  long long sum = 0, x = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') x = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    sum = sum * 10 + ch - '0';
    ch = getchar();
  }
  return sum * x;
}
inline void write(long long x) {
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  if (x > 9) write(x / 10);
  putchar(x % 10 + '0');
  return;
}
signed main() {
  n = read();
  m = read();
  for (register int i = 1; i <= n; ++i) ++a[x = read()];
  memset(dp, -0x3f, sizeof(dp));
  ans = dp[m][f] = a[0] + a[m];
  for (register int i = m + 1; i <= x; ++i)
    for (register int j = -320; j <= 320; ++j) {
      if (m + j > 0 && m + j <= i)
        dp[i][f + j] =
            max(dp[i][f + j],
                max(max(dp[i - (m + j)][f + j - 1], dp[i - (m + j)][f + j]),
                    dp[i - (m + j)][f + j + 1]) +
                    a[i]);
      ans = max(ans, dp[i][f + j]);
    }
  write(ans);
  return 0;
}
