#include <bits/stdc++.h>
using namespace std;
int dx[4] = {0, 0, 1, -1};
int dy[4] = {1, -1, 0, 0};
long long n, d, pos[30002], dp[30002][500], mx, ans = 0;
bool vis[30050][999];
int solve(int x, int y) {
  if (x > mx or y == 0)
    return 0;
  else if (vis[x][y])
    return dp[x][y];
  else
    dp[x][y] = pos[x] + max(solve(x + y, y), max(solve(x + y - 1, y - 1),
                                                 solve(x + y + 1, y + 1)));
  vis[x][y] = true;
  return dp[x][y];
}
int main() {
  cin >> n >> d;
  memset(pos, 0, sizeof pos);
  memset(vis, false, sizeof vis);
  for (int i = 1; i <= n; i++) {
    long long x;
    cin >> x;
    mx = max(mx, x);
    pos[x]++;
  }
  cout << solve(d, d) << endl;
}
