#include <bits/stdc++.h>
using namespace std;
void lc() { cout << endl; }
long long md(long long n) { return n % 998244353; }
long long val[30001], dp[30001][501], n, d;
long long res(long long i, long long j) {
  if (i > 30000) return 0;
  if (i == 30000) return val[i];
  if (j == 0) return 0;
  long long jump = j - d + 250;
  if (dp[i][jump] != -1) return dp[i][jump];
  long long r =
      val[i] + max(res(i + j, j + 1), max(res(i + j, j - 1), res(i + j, j)));
  return dp[i][jump] = r;
}
void solve() {
  memset(dp, -1, sizeof(dp));
  cin >> n >> d;
  for (long long i = 0; i < n; i++) {
    long long p;
    cin >> p;
    val[p]++;
  }
  cout << res(0, d);
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long t = 1;
  while (t--) {
    solve();
    lc();
  }
}
