#include <bits/stdc++.h>
using namespace std;
int w[30005];
int dp[30005][455];
int has[455];
int nhas[30005];
int main() {
  int n, d;
  scanf("%d%d", &n, &d);
  int top = 0;
  for (int i = d;; i++) {
    if ((i - d + 1) * (i + d) / 2 > 30000) break;
    has[++top] = i;
    nhas[i] = top;
  }
  for (int i = d - 1; i >= 1; i--) {
    if ((d + i) * (d - i + 1) / 2 > 30000) break;
    has[++top] = i;
    nhas[i] = top;
  }
  for (int i = 1;; i++) {
    if ((1 + i) * i / 2 > 30000) break;
    if (nhas[i] > 0) continue;
    has[++top] = i;
    nhas[i] = top;
  }
  for (int i = 0; i < n; i++) {
    int v;
    scanf("%d", &v);
    w[v]++;
  }
  memset(dp, -1, sizeof(dp));
  dp[d][nhas[d]] = w[d];
  for (int i = d; i <= 30000; i++) {
    for (int j = 1; j <= top; j++) {
      int val = dp[i][j];
      if (val == -1) continue;
      int to1 = nhas[has[j]];
      int to2 = nhas[has[j] - 1];
      int to3 = nhas[has[j] + 1];
      if (to1 > 0 && i + has[j] <= 30000)
        dp[i + has[j]][to1] = max(dp[i + has[j]][to1], val + w[i + has[j]]);
      if (to2 > 0 && has[j] - 1 > 0 && i + has[j] - 1 <= 30000)
        dp[i + has[j] - 1][to2] =
            max(dp[i + has[j] - 1][to2], val + w[i + has[j] - 1]);
      if (to3 > 0 && i + has[j] + 1 <= 30000)
        dp[i + has[j] + 1][to3] =
            max(dp[i + has[j] + 1][to3], val + w[i + has[j] + 1]);
    }
  }
  int ans = 0;
  for (int i = 1; i <= 30000; i++)
    for (int j = 1; j <= 450; j++)
      if (dp[i][j] > ans) ans = dp[i][j];
  printf("%d\n", ans);
  return 0;
}
