#include <bits/stdc++.h>
using namespace std;
const int ma = 400, N = 30000;
int n, d, gem[30005];
int dp[30001][801];
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
int main() {
  n = read();
  d = read();
  int a;
  int loend;
  for (int i = 0; i < n; i++) {
    a = read();
    gem[a]++;
  }
  for (int i = 0; i <= 30000; ++i) {
    for (int j = -ma; j <= ma; ++j) {
      dp[i][j + ma] = -1000000000;
    }
  }
  dp[d][0 + ma] = gem[0] + gem[d];
  for (int i = d; i < N; ++i) {
    for (int j = -ma; j <= ma; ++j) {
      if (dp[i][j + ma] == -1000000000) {
        continue;
      }
      for (int z = -1; z <= 1; z++) {
        int len = j + d + z;
        if (j + z < -ma || j + z > ma || len < 1 || i + len > N) {
          continue;
        }
        dp[i + len][j + z + ma] =
            max(dp[i + len][j + z + ma], dp[i][j + ma] + gem[i + len]);
      }
    }
  }
  int ans = 0;
  for (int i = 0; i <= N; ++i) {
    for (int j = -ma; j <= ma; ++j) {
      ans = max(ans, dp[i][j + ma]);
    }
  }
  printf("%d\n", ans);
  return 0;
}
