#include <bits/stdc++.h>
using namespace std;
int getint() {
  int s = 0, o = 1;
  char c;
  for (c = getchar(); c < '0' || c > '9'; c = getchar())
    if (c == '-') o = -1;
  for (; c >= '0' && c <= '9'; c = getchar()) s *= 10, s += c - '0';
  return s * o;
}
const int maxn = 30005;
int gem[maxn];
int a[maxn];
int dp[maxn][601], all, len, n, x;
inline void up(int &a, int b) {
  if (a < b) a = b;
}
int main(int argc, char const *argv[]) {
  n = getint(), len = getint();
  for (int i = 0; i < n; i++) {
    x = getint();
    gem[x]++;
    all = max(all, x);
  }
  int r = 0;
  dp[len][0 + 300] = gem[len] + 1;
  for (int i = 0; i <= all; ++i)
    for (int j = -300; j < 300; ++j)
      if (dp[i][j + 300]) {
        r = max(r, dp[i][j + 300] - 1);
        if (len + j > 0 && i + len + j - 1 <= all)
          up(dp[i + len + j - 1][j - 1 + 300],
             dp[i][j + 300] + gem[i + len + j - 1]);
        if (i + len + j <= all)
          up(dp[i + len + j][j + 300], dp[i][j + 300] + gem[i + len + j]);
        if (i + len + j + 1 <= all)
          up(dp[i + len + j + 1][j + 1 + 300],
             dp[i][j + 300] + gem[i + len + j + 1]);
      }
  printf("%d\n", r);
  return 0;
}
