#include <bits/stdc++.h>
using namespace std;
int p[31111], dp[31111][800];
int main() {
  int i, j, n, d, u;
  scanf("%d%d", &n, &d);
  for (i = 0; i < n; i++) {
    scanf("%d", &u);
    p[u]++;
  }
  for (i = 0; i <= 30000; i++) {
    for (j = 0; j <= 650; j++) {
      dp[i][j] = -10000000;
    }
  }
  int ans = dp[d][300] = p[d];
  for (i = d + 1; i <= 30000; i++) {
    for (j = 1; j <= 600; j++) {
      int pre = i - j - d + 300;
      if (pre < 0) break;
      if (pre >= i) continue;
      dp[i][j] = max(dp[pre][j], max(dp[pre][j + 1], dp[pre][j - 1])) + p[i];
      ans = max(ans, dp[i][j]);
    }
  }
  printf("%d\n", ans);
  return 0;
}
