#include <bits/stdc++.h>
using namespace std;
const int N = 30001;
const int OFFSET = 260;
int n, d;
int gems[N], dp[N][OFFSET * 2];
int solve(int i, int j) {
  int jump = d + j - OFFSET;
  if (jump <= 0 or i >= N) return 0;
  if (dp[i][j] != -1) return dp[i][j];
  int ans = 0;
  for (int length = -1; length <= 1; length++)
    if ((i + jump + length) >= 0 and (i + jump + length) < N)
      ans = max(ans, solve(i + jump + length, j + length));
  return dp[i][j] = (gems[i] + ans);
}
int main() {
  cin >> n >> d;
  memset(gems, 0, sizeof(gems));
  int island;
  for (int i = 0; i < n; i++) {
    cin >> island;
    gems[island]++;
  }
  memset(dp, -1, sizeof(dp));
  cout << solve(d, OFFSET);
  return 0;
}
