#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e4 + 10;
int dp[500][maxn], num[maxn];
int main() {
  memset(dp, -1, sizeof dp);
  memset(num, 0, sizeof num);
  int n, d, x, maxm = 0;
  cin >> n >> d;
  for (int i = 0; i < n; i++) {
    scanf("%d", &x);
    num[x]++;
  }
  int ans = num[d];
  dp[250][d] = num[d];
  for (int j = d; j < maxn; j++)
    for (int i = 1; i < 500; i++)
      if (dp[i][j] != -1) {
        int l = i - 250 + d;
        for (int k = -1; k <= 1; k++) {
          if (j + l + k < 1 || j + l + k > maxn || l + k < 1) continue;
          dp[i + k][l + j + k] =
              max(dp[i + k][j + l + k], dp[i][j] + num[l + j + k]);
          ans = max(ans, dp[i + k][j + l + k]);
        }
      }
  cout << ans;
  return 0;
}
