#include <bits/stdc++.h>
using namespace std;
int n, d, f[30005];
int x, dqj;
int dp[30005][1205];
int ans;
const int INF = 19950920;
int main() {
  scanf("%d", &n);
  scanf("%d", &d);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &x);
    f[x]++;
  }
  for (int i = 1; i <= 30000; ++i)
    for (int j = 0; j <= 1200; ++j) dp[i][j] = -INF;
  dp[d][600] = f[d];
  for (int i = d; i <= 30000; ++i)
    for (int j = 0; j <= 1200; ++j) {
      dqj = j - 600 + d;
      if (dqj <= 0) continue;
      if (dqj > 1 && i + dqj - 1 <= 30000)
        dp[i + dqj - 1][j - 1] =
            max(dp[i + dqj - 1][j - 1], dp[i][j] + f[i + dqj - 1]);
      if (i + dqj <= 30000)
        dp[i + dqj][j] = max(dp[i + dqj][j], dp[i][j] + f[i + dqj]);
      if (i + dqj + 1 <= 30000)
        dp[i + dqj + 1][j + 1] =
            max(dp[i + dqj + 1][j + 1], dp[i][j] + f[i + dqj + 1]);
    }
  ans = -INF;
  for (int i = 0; i <= 30000; ++i)
    for (int j = 0; j <= 1200; ++j) ans = max(ans, dp[i][j]);
  printf("%d\n", ans);
  return 0;
}
