#include <bits/stdc++.h>
using namespace std;
const int inf = 1000000000;
int e;
int dp[30002][500];
map<int, int> m;
int d;
int solve(int s, int l) {
  int j = l - (d - 250);
  if (s > e || s < 0) return 0;
  if (dp[s][j] != -1)
    return dp[s][j];
  else {
    if (l > 1)
      return dp[s][j] = max(max(solve(s + l + 1, l + 1), solve(s + l, l)),
                            solve(s + l - 1, l - 1)) +
                        m[s];
    else
      return dp[s][j] = max(solve(s + l + 1, l + 1), solve(s + l, l)) + m[s];
  }
}
int main() {
  int n, l, i, a;
  cin >> n >> d;
  for (i = 0; i < n; i++) {
    cin >> a;
    m[a]++;
    e = max(e, a);
  }
  memset(dp, -1, sizeof(dp));
  cout << solve(d, d);
}
