#include <bits/stdc++.h>
using namespace std;
int gems[30001], dp[30001][600], d;
int solve(int i, int j) {
  if (i >= 30001 || j + d - 300 == 0) return 0;
  if (dp[i][j] != -1) return dp[i][j];
  dp[i][j] = 0;
  dp[i][j] = solve(i + j + d - 300, j - 1);
  dp[i][j] = max(dp[i][j], solve(i + j + d - 300, j));
  dp[i][j] = max(dp[i][j], solve(i + j + d - 300, j + 1));
  dp[i][j] += gems[i];
  return dp[i][j];
}
int main() {
  int i, j, t, n;
  cin >> n >> d;
  for (i = 0; i < 30001; i++) gems[i] = 0;
  for (i = 0; i < n; i++) {
    cin >> t;
    gems[t]++;
  }
  for (i = 0; i < 30001; i++)
    for (j = 0; j < 600; j++) dp[i][j] = -1;
  cout << solve(0, 300);
  return 0;
}
