#include <bits/stdc++.h>
using namespace std;
long long dp[30005][1005];
int ar[30005], n, d, mx = 0;
long long f(int i, int pre) {
  if (i >= mx) return 0;
  if (dp[i][pre - (d - 250)] != -1) return dp[i][pre - (d - 250)];
  long long value = 0;
  if (i + pre <= mx) value = max(value, f(i + pre, pre) + ar[i + pre]);
  if (i + pre + 1 <= mx)
    value = max(value, f(i + pre + 1, pre + 1) + ar[i + pre + 1]);
  if (i + pre - 1 <= mx)
    if (pre != 1) value = max(value, f(i + pre - 1, pre - 1) + ar[i + pre - 1]);
  return dp[i][pre - (d - 250)] = value;
}
int main(void) {
  memset(dp, -1, sizeof(dp));
  memset(ar, 0, sizeof(ar));
  scanf("%d %d", &n, &d);
  for (int i = 0; i < n; i++) {
    int in;
    scanf("%d", &in);
    ar[in]++;
    mx = max(mx, in);
  }
  printf("%lld\n", f(d, d) + ar[d]);
  return 0;
}
