#include <bits/stdc++.h>
using namespace std;
int n, m, i, j, k, d, k1, l, ans, dp[30001][550], a[30001];
bool used[30001][550];
int solve(int i, int j) {
  if (i >= 30001) return 0;
  int jj = j - (d - 250);
  if (used[i][jj]) return dp[i][jj];
  used[i][jj] = 1;
  int res = 0;
  if (j == 1) {
    res = a[i] + (max(solve(i + j, j), solve(i + j + 1, j + 1)));
  } else {
    res = a[i] + (max(solve(i + j - 1, j - 1),
                      max(solve(i + j, j), solve(i + j + 1, j + 1))));
  }
  dp[i][jj] = res;
  return res;
}
int main() {
  scanf("%d%d", &n, &d);
  for (i = 1; i <= n; i++) {
    scanf("%d", &k);
    a[k]++;
  }
  printf("%d\n", solve(d, d));
  return 0;
}
