#include <bits/stdc++.h>
using namespace std;
int val[30010], dp[30010][510], f[30010][510], d, vis[30010][510], ans;
int main() {
  int T, t, n, m, i, j, k, u, v, l, l2, q;
  scanf("%d%d", &n, &d);
  for (i = 1; i <= n; i++) {
    scanf("%d", &k);
    val[k]++;
  }
  f[d][0] = 1;
  f[d][1] = 250;
  dp[d][250] = val[d];
  ans = val[d];
  for (i = d; i <= 30000; i++) {
    for (j = 1; j <= f[i][0]; j++) {
      l = f[i][j] + d - 250;
      for (k = -1; k <= 1; k++) {
        l2 = l + k;
        v = i + l2;
        q = l2 - d + 250;
        if (l2 > 0 && v <= 30000) {
          dp[v][q] = max(dp[v][q], dp[i][f[i][j]] + val[v]);
          ans = max(ans, dp[v][q]);
          if (vis[v][q] == 0) {
            vis[v][q] = 1;
            f[v][0]++;
            f[v][f[v][0]] = q;
          }
        }
      }
    }
  }
  printf("%d\n", ans);
}
