#include <bits/stdc++.h>
using namespace std;
int n, d, tr[30010], ans, ed;
int f[30010][500];
bool vis[30010][500];
void getm(int &a, int b) { a = a > b ? a : b; }
void getans() {
  f[d][250] = tr[d];
  vis[d][250] = 1;
  for (int i = d; i <= ed; ++i)
    for (int j = 0; j < 500; ++j) {
      if (!vis[i][j]) continue;
      ans = ans > f[i][j] ? ans : f[i][j];
      int tmp = d - 250 + j;
      if (tmp - 1 > 0 && i + tmp - 1 <= ed) {
        vis[i + tmp - 1][j - 1] = 1;
        getm(f[i + tmp - 1][j - 1], f[i][j] + tr[i + tmp - 1]);
      }
      if (tmp > 0 && i + tmp <= ed) {
        vis[i + tmp][j] = 1;
        getm(f[i + tmp][j], f[i][j] + tr[i + tmp]);
      }
      if (tmp + 1 > 0 && i + tmp + 1 <= ed) {
        vis[i + tmp + 1][j + 1] = 1;
        getm(f[i + tmp + 1][j + 1], f[i][j] + tr[i + tmp + 1]);
      }
    }
  printf("%d\n", ans);
}
int main() {
  scanf("%d%d", &n, &d);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &ed);
    ++tr[ed];
  }
  getans();
  return 0;
}
