#include <bits/stdc++.h>
using namespace std;
const long long N = 3e4 + 10, M = 1e3 + 10;
long long n, p[N], d, dp[N][M + 10];
long long solve(long long pos, long long L) {
  if (pos > 30000) return 0;
  long long wh = L - d + M / 2;
  if (dp[pos][wh] != -1) return dp[pos][wh];
  long long ret = 0;
  if (L == 1)
    ret = max(solve(pos + L, L), solve(pos + L + 1, L + 1));
  else
    ret = max({solve(pos + L - 1, L - 1), solve(pos + L, L),
               solve(pos + L + 1, L + 1)});
  ret += p[pos];
  dp[pos][wh] = ret;
  return ret;
}
int main() {
  for (long long i = 0; i < N; i++)
    for (long long j = 0; j < M; j++) dp[i][j] = -1;
  cin >> n >> d;
  for (long long i = 1; i <= n; i++) {
    long long x;
    cin >> x;
    p[x]++;
  }
  cout << solve(d, d) << '\n';
}
