#include <bits/stdc++.h>
int a[30100];
int dp[30100][520];
int main(void) {
  int n, d, dd;
  int i, j, jj;
  int aa;
  int ans, temp, temp2;
  while (scanf("%d %d", &n, &d) != EOF) {
    for (i = 0; i <= 30000; i++) {
      a[i] = 0;
    }
    dd = 1;
    for (i = 1; i <= n; i++) {
      scanf("%d", &aa);
      a[aa]++;
      if (aa == d) {
        dd++;
      }
    }
    for (i = 0; i <= 30000; i++) {
      for (j = 9; j <= 511; j++) {
        dp[i][j] = 0;
      }
    }
    dp[d][260] = dd;
    ans = dd;
    for (i = d + 1; i <= 30000; i++) {
      for (j = 10; j <= 510; j++) {
        jj = d + j - 260;
        if (jj > 0) {
          if (i - jj >= d) {
            temp = dp[i - jj][j];
            if (jj - 1 > 0) {
              temp2 = dp[i - jj][j - 1];
              if (temp2 > temp) {
                temp = temp2;
              }
            }
            temp2 = dp[i - jj][j + 1];
            if (temp2 > temp) {
              temp = temp2;
            }
            if (temp) {
              temp += a[i];
              if (temp > ans) {
                ans = temp;
              }
              dp[i][j] = temp;
            }
          }
        }
      }
    }
    printf("%d\n", ans - 1);
  }
  return 0;
}
