#include <bits/stdc++.h>
using namespace std;
int n, d;
int px[30001];
int dp1[30001][601];
int tru[30001];
int lim;
int dp2[30001][1000];
int main() {
  scanf("%d%d", &n, &d);
  int ans = 0;
  int now = 1;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &px[i]);
    tru[px[i]]++;
    if (px[i] == d) {
      ans++;
      now = i + 1;
    }
  }
  lim = 300;
  for (int i = 1; i <= 30000; i++)
    for (int j = 0; j <= 2 * lim; j++) dp1[i][j] = dp2[i][j] = -1;
  if (d > lim) {
    dp1[d][300] = ans;
    int pp = 600;
    for (int i = d; i <= 30000; i++) {
      for (int j = 0; j <= pp; j++) {
        if (dp1[i][j] == -1) continue;
        int step = d + j - 300;
        ans = max(ans, dp1[i][j]);
        if (step != 0 && i + step <= 30000)
          dp1[i + step][step - d + 300] =
              max(dp1[i + step][step - d + 300], dp1[i][j] + tru[i + step]);
        if (i + step - 1 <= 30000)
          dp1[i + step - 1][step - 1 - d + 300] =
              max(dp1[i + step - 1][step - 1 - d + 300],
                  dp1[i][j] + tru[i + step - 1]);
        if (step - d + 1 + 300 <= pp && i + step + 1 <= 30000)
          dp1[i + step + 1][step + 1 - d + 300] =
              max(dp1[i + step + 1][step + 1 - d + 300],
                  dp1[i][j] + tru[i + step + 1]);
      }
    }
    printf("%d\n", ans);
  } else {
    dp2[d][d] = ans;
    int pp = 600;
    for (int i = d; i <= 30000; i++) {
      for (int j = 1; j <= pp; j++) {
        if (dp2[i][j] == -1) continue;
        ans = max(ans, dp2[i][j]);
        if (j != 0 && i + j <= 30000)
          dp2[i + j][j] = max(dp2[i + j][j], dp2[i][j] + tru[i + j]);
        if (j > 1 && i + j - 1 <= 30000)
          dp2[i + j - 1][j - 1] =
              max(dp2[i + j - 1][j - 1], dp2[i][j] + tru[i + j - 1]);
        if (j + 1 <= pp && i + j + 1 <= 30000)
          dp2[i + j + 1][j + 1] =
              max(dp2[i + j + 1][j + 1], dp2[i][j] + tru[i + j + 1]);
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}
