#include <bits/stdc++.h>
using namespace std;
const int MAXN = 3e4, SQN = 3e2;
map<int, int> dst_idx, idx_dst;
int n, d, dp[MAXN + 3][SQN + 3], a[MAXN + 3], max_idx;
int fazdp(int idx, int li) {
  if (dp[idx][li] != -1) return dp[idx][li];
  int di = idx_dst[li];
  int ret = 0;
  for (int i = -1; i <= 1; i++) {
    int dd = di + i;
    if (dst_idx.find(dd) == dst_idx.end() || dd <= 0 || idx + dd > max_idx)
      continue;
    int iidx = idx + dd;
    ret = max(ret, fazdp(iidx, dst_idx[dd]));
  }
  return dp[idx][li] = a[idx] + ret;
}
int main() {
  for (int i = 0; i < MAXN + 3; i++)
    for (int j = 0; j < SQN + 3; j++) dp[i][j] = -1;
  scanf("%d %d", &n, &d);
  for (int i = 1; i <= n; i++) {
    int aux;
    scanf("%d", &aux);
    max_idx = max(max_idx, aux);
    a[aux]++;
  }
  int cnt = 0;
  for (int i = max(1, d - SQN); i <= min(max_idx, d + SQN); i++) {
    dst_idx[i] = cnt;
    idx_dst[cnt] = i;
    cnt++;
  }
  printf("%d", a[0] + fazdp(d, dst_idx[d]));
}
