#include <bits/stdc++.h>
using namespace std;
long long idx[30001];
long long dp[30001][501];
long long a[30001];
long long n, d;
long long solve(long long ind, long long d) {
  long long sd = idx[d];
  if (ind > 30000) return 0;
  if (dp[ind][sd] != -1) return dp[ind][sd];
  long long r1 = solve(ind + d, d);
  long long r2 = solve(ind + d + 1, d + 1);
  long long r3 = 0;
  if (d - 1) r3 = solve(ind + d - 1, d - 1);
  return dp[ind][sd] = a[ind] + max(r1, max(r2, r3));
}
int main() {
  scanf("%lld", &n);
  scanf("%lld", &d);
  long long sd = 1;
  for (long long i = max(d - 245, 0LL); i <= min(d + 245, 30000LL); i++)
    idx[i] = sd++;
  memset(dp, -1, sizeof dp);
  for (long long i = 1; i <= n; i++) {
    long long x;
    scanf("%lld", &x);
    a[x]++;
  }
  cout << solve(d, d) << endl;
  return 0;
}
