#include <bits/stdc++.h>
using namespace std;
long long n, x, d, a[30005], dp[30005][505];
long long DP(long long idx, long long jump) {
  if (idx >= 30001) return 0;
  long long jump_fit = jump - (d - 250);
  long long &ret = dp[idx][jump_fit];
  if (ret != -1) return ret;
  if (jump == 1)
    ret = a[idx] + max(DP(idx + jump, jump), DP(idx + jump + 1, jump + 1));
  else
    ret = a[idx] + max(DP(idx + jump - 1, jump - 1),
                       max(DP(idx + jump, jump), DP(idx + jump + 1, jump + 1)));
  return ret;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> d;
  for (long long i = 0; i < n; i++) cin >> x, a[x]++;
  memset(dp, -1, sizeof(dp));
  cout << DP(d, d) << endl;
  return 0;
}
