#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const double pi = 3.141592653589793238462643383279;
int n, d, x;
int dp[30005][1005], gems[30005];
bool vis[30005][1005];
int solve(int i, int jump) {
  int j = jump - d;
  if (i > 30000) return 0;
  if (vis[i][j]) return dp[i][j];
  int t = 0;
  vis[i][j] = 1;
  t = max(solve(i + jump, jump), solve(i + jump + 1, jump + 1));
  if (jump != 1) t = max(solve(i + jump - 1, jump - 1), t);
  return dp[i][j] = t + gems[i];
}
signed main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  long long testCases = 1;
  while (testCases--) {
    cin >> n >> d;
    for (int i = 0; i < n; i++) {
      cin >> x;
      gems[x]++;
    }
    cout << solve(d, d);
  }
}
