#include <bits/stdc++.h>
using namespace std;
long long n, d, g[30001], dp[30001][246 * 2];
bool visit[30001][246 * 2];
long long solve(long long i, long long j) {
  long long j2 = j + 246 - d;
  if (i >= 30001) return 0;
  if (visit[i][j2]) {
    return dp[i][j2];
  }
  visit[i][j2] = true;
  if (j == 1) {
    dp[i][j2] = g[i] + max(solve(i + j, j), solve(i + j + 1, j + 1));
  } else {
    dp[i][j2] = g[i] + max(solve(i + j - 1, j - 1),
                           max(solve(i + j, j), solve(i + j + 1, j + 1)));
  }
  return dp[i][j2];
}
int main() {
  long long p;
  memset(g, 0, sizeof(g));
  memset(visit, false, sizeof(visit));
  cin >> n >> d;
  while (n--) {
    cin >> p;
    g[p]++;
  }
  cout << solve(d, d);
  return 0;
}
