#include <bits/stdc++.h>
using namespace std;
int memo[30001][250 * 2];
int arr[30004], mx, d;
int solve(int ind, int l) {
  if (ind > mx) return 0;
  int &ret = memo[ind][l - (d - 250)];
  if (ret != -1) return ret;
  ret = -INT_MAX;
  ret = max(ret, solve(ind + l, l) + arr[ind]);
  if (l > 1) ret = max(ret, solve(ind + l - 1, l - 1) + arr[ind]);
  ret = max(ret, solve(ind + l + 1, l + 1) + arr[ind]);
  return ret;
}
int main() {
  int n, in;
  scanf("%d %d", &n, &d);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &in);
    ++arr[in];
    mx = max(mx, in);
  }
  memset(memo, -1, sizeof(memo));
  printf("%d\n", solve(d, d));
  return 0;
}
