#include <bits/stdc++.h>
using namespace std;
int n, m;
int p[30010], f[30010][600];
int main() {
  scanf("%d%d", &n, &m);
  memset(f, -1, sizeof(f));
  for (int i = 1; i <= n; i++) {
    int aa;
    scanf("%d", &aa);
    p[aa]++;
  }
  f[m][250] = 0;
  int mx = 0;
  for (int i = m; i <= 30000; i++) {
    for (int j = -250; j <= 250; j++) {
      int v = m + j;
      int tmp = -1;
      if (v > i) break;
      if (v > 0 && f[i - v][j + 250] != -1) tmp = max(tmp, f[i - v][j + 250]);
      if (v > 1 && f[i - v][j + 249] != -1) tmp = max(tmp, f[i - v][j + 249]);
      if (v > 0 && f[i - v][j + 251] != -1) tmp = max(tmp, f[i - v][j + 251]);
      if (i != m) f[i][j + 250] = tmp;
      if (f[i][j + 250] != -1) f[i][j + 250] += p[i];
      mx = max(mx, f[i][j + 250]);
    }
  }
  printf("%d\n", mx);
  return 0;
}
