#include <bits/stdc++.h>
using namespace std;
const int N = 30500;
int dp[N][500], used[N][500], n, d, gem[N], x;
int solve(int i, int j) {
  int l = j - (d - 250);
  if (i > 30000) {
    return 0;
  }
  if (used[i][l]) {
    return dp[i][l];
  }
  used[i][l] = 1;
  int res = 0;
  if (j > 1) {
    res = gem[i] + max(solve(i + j - 1, j - 1),
                       max(solve(i + j, j), solve(i + j + 1, j + 1)));
  }
  if (j == 1) {
    res = gem[i] + max(solve(i + j, j), solve(i + j + 1, j + 1));
  }
  dp[i][l] = res;
  return res;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cin >> n >> d;
  for (int i = 1; i <= n; i++) {
    cin >> x;
    gem[x]++;
  }
  cout << solve(d, d);
  return 0;
}
