#include <bits/stdc++.h>
using namespace std;
const long long int no = 3e6 + 5, modulo = 1e9 + 7, inf = 1e18, N = 2e3 + 1;
const long double PI = 3.1415926535897932384;
long long int ar[no];
long long int dp[40000][500], mx = -1;
bool vis[40000][500];
long long int solve(long long int node, long long int l, long long int d) {
  long long int dist = l - (d - 250);
  if (node > mx) return 0;
  if (vis[node][dist]) return dp[node][dist];
  vis[node][dist] = 1;
  if (l == 1) {
    dp[node][dist] =
        max({solve(node + l, l, d), solve(node + l + 1, l + 1, d)}) + ar[node];
  } else {
    dp[node][dist] = max({solve(node + l, l, d), solve(node + l + 1, l + 1, d),
                          solve(node + l - 1, l - 1, d)}) +
                     ar[node];
  }
  return dp[node][dist];
}
void solve() {
  long long int n = 0, m = 0, a = 0, b = 0, c = 0, d = 0, x = 0, y = 0, z = 0,
                w = 0, k = 0;
  cin >> n >> d;
  for (long long int i = 0; i < n; i++) {
    cin >> x;
    ar[x]++;
    mx = max(mx, x);
  }
  cout << solve(d, d, d);
}
inline void runn() {}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  runn();
  long long int t = 1;
  cout << fixed << setprecision(15);
  for (long long int i = 1; i < t + 1; i++) {
    solve();
  }
}
