#include <bits/stdc++.h>
using namespace std;
const int maxn = 31000;
int dp[maxn][555], po[maxn];
int main() {
  int n, d, c;
  scanf("%d%d", &n, &d);
  for (int i = (0); i < (n); i++) scanf("%d", &c), po[c]++;
  memset(dp, -1, sizeof(dp));
  dp[d][275] = po[d];
  int ans = 0;
  for (int i = (d); i < (maxn); i++)
    for (int l = (0); l < (555); l++) {
      if (dp[i][l] < 0) continue;
      ans = max(ans, dp[i][l]);
      int len = d - 275 + l;
      if (len < 0) continue;
      if (len + i < maxn)
        dp[len + i][l] = max(dp[len + i][l], dp[i][l] + po[len + i]);
      if (len + i + 1 < maxn)
        dp[len + i + 1][l + 1] =
            max(dp[len + i + 1][l + 1], dp[i][l] + po[len + i + 1]);
      if (len + i - 1 < maxn && len)
        dp[len + i - 1][l - 1] =
            max(dp[len + i - 1][l - 1], dp[i][l] + po[len + i - 1]);
    }
  printf("%d\n", ans);
  return 0;
}
