#include <bits/stdc++.h>
using namespace std;
int n, d, p[30001];
bool is[30001][700];
int dp[30001][700];
int sol(int cur, int l) {
  if (cur > 30000) return 0;
  if (is[cur][l - d + 300]) return dp[cur][l - d + 300];
  int ans = 0;
  if (cur + l - 1 > cur) ans = max(ans, sol(cur + l - 1, l - 1));
  if (cur + l > cur) ans = max(ans, sol(cur + l, l));
  if (cur + l + 1 > cur) ans = max(ans, sol(cur + l + 1, l + 1));
  is[cur][l - d + 300] = 1;
  return dp[cur][l - d + 300] = ans + p[cur];
}
void solve() {
  cin >> n >> d;
  for (int i = 0; i < n; i++) {
    int first;
    cin >> first;
    p[first]++;
  }
  cout << sol(d, d) << '\n';
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
