#include <bits/stdc++.h>
using namespace std;
int n, d, m, a[30001], dp[30001][505];
bool used[30005][505];
int solve(int i, int j) {
  int jj = j - (d - 250), ans;
  if (i >= 30001) return 0;
  if (used[i][jj]) return dp[i][jj];
  used[i][jj] = true;
  if (j == 1)
    ans = a[i] + max(solve(i + j, j), solve(i + j + 1, j + 1));
  else
    ans = a[i] + max(solve(i + j + 1, j + 1),
                     max(solve(i + j, j), solve(i + j - 1, j - 1)));
  dp[i][jj] = ans;
  return ans;
}
int main() {
  cin >> n >> d;
  for (int i = 1; i <= n; i++) {
    cin >> m;
    a[m]++;
  }
  cout << solve(d, d);
}
