#include <bits/stdc++.h>
using namespace std;
int n, d, qtd[30050], dp[30050][600];
int solve(int i, int len) {
  if (i >= 30050) return 0;
  int dx = 300 + len - d;
  if (dp[i][dx] != -1) return dp[i][dx];
  int A = solve(i + len + 1, len + 1) + qtd[i];
  int B = (len > 0 ? solve(i + len, len) + qtd[i] : 0);
  int C = (len > 1 ? solve(i + len - 1, len - 1) + qtd[i] : 0);
  return dp[i][dx] = max(A, max(B, C));
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> d;
  for (int i = 1, x; i <= n; i++) cin >> x, qtd[x]++;
  memset(dp, -1, sizeof dp);
  cout << solve(d, d) << "\n";
}
