#include <bits/stdc++.h>
using namespace std;
const int maxn = 33333;
const int sp = 300;
const int inf = 987654321;
int f[maxn][900];
int gem[maxn];
int main() {
  int n, d;
  scanf("%d%d", &n, &d);
  int m = 30000;
  for (int i = 1; i <= n; ++i) {
    int k;
    scanf("%d", &k);
    ++gem[k];
  }
  for (int i = d; i <= m; ++i)
    for (int j = sp << 1; j >= 0; --j) f[i][j] = -inf;
  f[d][sp] = 0;
  for (int i = d; i <= m; ++i)
    for (int j = sp << 1; j >= 0; --j) {
      f[i][j] += gem[i];
      if (d + j - sp <= 0) continue;
      int v = i + d + j - sp;
      if (v <= m) f[v][j] = max(f[v][j], f[i][j]);
      if (v + 1 <= m) f[v + 1][j + 1] = max(f[v + 1][j + 1], f[i][j]);
      if (v - 1 <= m && d + j - sp > 1)
        f[v - 1][j - 1] = max(f[v - 1][j - 1], f[i][j]);
    }
  int ans = -inf;
  for (int i = d; i <= m; ++i)
    for (int j = sp << 1; j >= 0; --j) ans = max(ans, f[i][j]);
  printf("%d\n", ans);
  return 0;
}
