#include <bits/stdc++.h>
using namespace std;
const int N = 30001, M = 300;
int n, d;
int gem[N];
int dp[N][M << 1];
int solve(int i, int j) {
  if (i >= N) return 0;
  if (j <= 0) return 0;
  if (dp[i][M + j - d] != -1) return dp[i][M + j - d];
  return dp[i][M + j - d] =
             gem[i] + max(solve(i + j - 1, j - 1),
                          max(solve(i + j, j), solve(i + j + 1, j + 1)));
}
int main() {
  memset(dp, -1, sizeof dp);
  scanf("%d%d", &n, &d);
  while (n--) {
    int x;
    scanf("%d", &x);
    gem[x]++;
  }
  printf("%d\n", solve(d, d));
  return 0;
}
