#include <bits/stdc++.h>
using namespace std;
const int MAXK = 500;
int A[30001];
int dp[30001][2 * MAXK + 1];
int d;
int solve(int pos, int cur) {
  if (pos > 30000) return 0;
  assert(0 <= cur - d + MAXK && cur - d + MAXK <= 2 * MAXK);
  if (dp[pos][cur - d + MAXK] != -1) return dp[pos][cur - d + MAXK];
  return dp[pos][cur - d + MAXK] =
             A[pos] +
             max(max(solve(pos + cur, cur), solve(pos + cur + 1, cur + 1)),
                 (cur > 1) ? solve(pos + cur - 1, cur - 1) : 0);
}
int main() {
  int n;
  scanf("%d %d", &n, &d);
  for (int i = 0; i < (n); i++) {
    int x;
    scanf("%d", &x);
    A[x]++;
  }
  memset(dp, -1, sizeof dp);
  cout << solve(d, d) << endl;
  return 0;
}
