#include <bits/stdc++.h>
using namespace std;
const int N = 3e4, INF = int(1e9) + 1, mod = 1e9 + 7;
const long long BIG = 1e16;
int n, d, a[N + 5], dp[N + 5][250 * 2 + 5];
bool w[N + 5][250 * 2 + 5];
int rec(int v, int l) {
  if (v > N) {
    return 0;
  }
  int l1 = l - (d - 250);
  if (w[v][l1]) return dp[v][l1];
  int ans = 0;
  for (int i = -1; i <= 1; i++) {
    if (l + i) ans = max(ans, rec(v + l + i, l + i));
  }
  w[v][l1] = 1;
  ans += a[v];
  return dp[v][l1] = ans;
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> d;
  for (int i = 1; i <= n; i++) {
    int x;
    cin >> x;
    a[x]++;
  }
  cout << rec(d, d);
}
