#include <bits/stdc++.h>
using namespace std;
const int INF = 0x7ffffff;
const int dd_stand = 350;
int n, dd;
int dp[30048][700];
int g[30048];
inline int work(int ddd) { return dd_stand + (ddd - dd); }
int main() {
  int i, j, first, cur_dd;
  scanf("%d%d", &n, &dd);
  for (i = 1; i <= n; i++) {
    scanf("%d", &first);
    g[first]++;
  }
  int ans = -1;
  for (i = 0; i <= 30000; i++)
    for (j = 0; j <= 699; j++) dp[i][j] = -INF;
  dp[dd][dd_stand] = g[dd];
  ans = g[dd];
  for (i = dd + 1; i <= 30000; i++)
    for (j = dd_stand - 260; j <= dd_stand + 260; j++) {
      cur_dd = dd + (j - dd_stand);
      if (cur_dd <= 0) {
        dp[i][j] = -INF;
        continue;
      }
      if (i - cur_dd <= 0) {
        dp[i][j] = -INF;
        continue;
      }
      if (cur_dd > 1)
        dp[i][j] = max(dp[i][j], dp[i - cur_dd][work(cur_dd - 1)] + g[i]);
      dp[i][j] = max(dp[i][j], dp[i - cur_dd][work(cur_dd)] + g[i]);
      dp[i][j] = max(dp[i][j], dp[i - cur_dd][work(cur_dd + 1)] + g[i]);
      if (dp[i][j] > ans) {
        ans = dp[i][j];
      }
    }
  printf("%d\n", ans);
  return 0;
}
