#include <bits/stdc++.h>
using namespace std;
int cnt[50000];
int dp[30010][1100], ans = 0;
int main() {
  memset(dp, -0x3f, sizeof(dp));
  int inf = dp[0][0];
  int n, d;
  scanf("%d%d", &n, &d);
  int mx = max(0, d - 500);
  for (int i = 1; i <= n; i++) {
    int x;
    scanf("%d", &x);
    cnt[x]++;
  }
  dp[d][d - mx] = cnt[d];
  for (int i = 1; i <= 30000; i++)
    for (int j = max(1, d - 500); j <= min(30000, d + 500); j++) {
      int k = j - mx;
      if (j != 1) {
        if (i + j - 1 > 30000)
          ans = max(ans, dp[i][k]);
        else
          dp[i + j - 1][k - 1] =
              max(dp[i + j - 1][k - 1], dp[i][k] + cnt[i + j - 1]);
      }
      if (i + j > 30000)
        ans = max(ans, dp[i][k]);
      else
        dp[i + j][k] = max(dp[i + j][k], dp[i][k] + cnt[i + j]);
      if (i + j + 1 > 30000)
        ans = max(ans, dp[i][k]);
      else
        dp[i + j + 1][k + 1] =
            max(dp[i + j + 1][k + 1], dp[i][k] + cnt[i + j + 1]);
    }
  printf("%d", ans);
  return 0;
}
