#include <bits/stdc++.h>
using namespace std;
int dp[30005][1000];
int b[30005];
int main() {
  int n, d;
  memset(b, 0, sizeof(b));
  memset(dp, 0, sizeof(dp));
  scanf("%d %d", &n, &d);
  int maxn = 0;
  for (int i = 1; i <= n; i++) {
    int x;
    scanf("%d", &x);
    b[x]++;
    if (x > maxn) maxn = x;
  }
  int ans = b[d] + 1;
  dp[d][500] = b[d] + 1;
  for (int i = d + 1; i <= maxn; i++) {
    for (int j = 1; j < 1000; j++) {
      if (d + (j - 500) > 0) {
        if (i - (d + (j - 500)) < d) continue;
        if (dp[i - (d + (j - 500))][j + 1])
          dp[i][j] = max(dp[i][j], dp[i - (d + (j - 500))][j + 1]);
        if (dp[i - (d + (j - 500))][j])
          dp[i][j] = max(dp[i][j], dp[i - (d + (j - 500))][j]);
        if (d + (j - 500) > 1)
          if (dp[i - (d + (j - 500))][j - 1])
            dp[i][j] = max(dp[i][j], dp[i - (d + (j - 500))][j - 1]);
        if (dp[i][j]) dp[i][j] += b[i];
        if (dp[i][j] > ans) ans = dp[i][j];
      }
    }
  }
  printf("%d\n", ans - 1);
}
