#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:1000000000")
using namespace std;
const int inf = (int)1e9 + 7;
const double eps = 1e-10;
const int M = 400;
const int N = 30001;
const long long P = (long long)1e9 + 7;
const int K = 11;
clock_t start = clock();
int c[N];
int dp[N][M];
int n, k;
int main() {
  int n, k;
  scanf("%d %d", &n, &k);
  memset(dp, -1, sizeof dp);
  for (int i = 0; i < n; ++i) {
    int p;
    scanf("%d", &p);
    c[p]++;
  }
  int l = k;
  for (;; l--)
    if (k * (k + 1) / 2 - l * (l - 1) / 2 >= N) break;
  l = max(l + 1, 0);
  dp[k][k - l] = c[k];
  for (int i = k + 1; i < N; ++i)
    for (int j = l; j < M + l; ++j)
      if (i >= j) {
        int s = -1;
        if (j > l)
          s = max(dp[i - j][j - l],
                  max(dp[i - j][j - l - 1], dp[i - j][j - l + 1]));
        else
          s = max(dp[i - j][j - l], dp[i - j][j - l + 1]);
        if (s != -1) dp[i][j - l] = max(dp[i][j - l], s + c[i]);
      }
  int ans = 0;
  for (int i = 0; i < N; ++i)
    for (int j = 0; j < M; ++j) ans = max(ans, dp[i][j]);
  printf("%d", ans);
  return 0;
}
