#include <bits/stdc++.h>
using namespace std;
const int maxn = 30005;
const int maxm = 800;
const int base = 400;
int c[maxn];
int n, d;
int f[maxn][maxm];
void pd(int &ret, int val) {
  if (ret < val) ret = val;
}
int main() {
  scanf("%d%d", &n, &d);
  for (int i = 1; i <= n; i++) {
    int x;
    scanf("%d", &x);
    c[x]++;
  }
  memset(f, -1, sizeof(f));
  f[d][base] = c[d];
  for (int i = d; i < maxn; i++)
    for (int j = 0; j < maxm; j++) {
      if (f[i][j] == -1) continue;
      int tt = j - base + d;
      if (tt > 0 && i + tt < maxn) pd(f[i + tt][j], f[i][j] + c[i + tt]);
      if (tt + 1 > 0 && i + tt + 1 < maxn)
        pd(f[i + tt + 1][j + 1], f[i][j] + c[i + tt + 1]);
      if (tt - 1 > 0 && i + tt - 1 < maxn && j)
        pd(f[i + tt - 1][j - 1], f[i][j] + c[i + tt - 1]);
    }
  int ret = 0;
  for (int i = 0; i < maxn; i++)
    for (int j = 0; j < maxm; j++) pd(ret, f[i][j]);
  printf("%d\n", ret);
  return 0;
}
