#include <bits/stdc++.h>
using namespace std;
int n, d, res;
int cnt[30030];
int dp[30030][500];
void readin() {
  scanf("%d%d", &n, &d);
  int temp;
  for (int i = 0; i < (n); i++) {
    scanf("%d", &temp);
    cnt[temp]++;
  }
}
void init() {
  res = cnt[d];
  for (int i = 0; i < (30030); i++)
    for (int j = int(-250); j <= int(249); j++) dp[i][j + 250] = -1000000001;
}
void process() {
  dp[d][250] = cnt[d];
  int u, v, next, c;
  for (int i = int(d); i <= int(30000); i++) {
    for (int k = -250; k < 249; k++) {
      int u = d + k;
      if (u < 1) continue;
      for (int j = int((u > 1) ? -1 : 0); j <= int(1); j++) {
        next = i + u + j;
        if (next <= 30000) {
          c = dp[i][k + 250] + cnt[next];
          dp[next][k + j + 250] = max(dp[next][k + j + 250], c);
          if (c > res) res = c;
        }
      }
    }
  }
}
void writeout() { printf("%d\n", res); }
int main() {
  readin();
  init();
  process();
  writeout();
  return 0;
}
