#include <bits/stdc++.h>
using namespace std;
using namespace std;
int a[30005], dp[30005][505];
int main() {
  int n, d, mxd, t1, ans = 0;
  scanf("%d%d", &n, &d);
  for (int i = 0; i < n; i++) {
    scanf("%d", &mxd);
    a[mxd]++;
  }
  memset(dp, 170, sizeof(dp));
  dp[d][245] = a[d];
  for (int i = 1; i <= 30000; i++) {
    for (int j = 0; j < 491; j++) {
      if (dp[i][j] < 0) continue;
      ans = max(ans, dp[i][j]);
      t1 = j - 245 + d;
      if (t1 <= 0 || i + t1 > 30000) {
        continue;
      }
      dp[i + t1 + 1][j + 1] =
          max(dp[i + t1 + 1][j + 1], dp[i][j] + a[i + t1 + 1]);
      dp[i + t1][j] = max(dp[i + t1][j], dp[i][j] + a[i + t1]);
      dp[i + t1 - 1][j - 1] =
          max(dp[i + t1 - 1][j - 1], dp[i][j] + a[i + t1 - 1]);
    }
  }
  printf("%d\n", ans);
  return 0;
}
