#include <bits/stdc++.h>
using namespace std;
ifstream fin("in.in");
ofstream fout("out.out");
const int N = 3e4 + 10, inf = -1e9;
int n, d, base, cnt[N], dp[N][2 * 245 + 10];
int calc(int pos, int l) {
  if (pos >= N || l < base) return 0;
  int &res = dp[pos][l - base];
  if (res != -1) return res;
  res = max(calc(pos + l, l), calc(pos + l + 1, l + 1));
  res = max(res, calc(pos + l - 1, l - 1));
  res += cnt[pos];
  return res;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> d;
  for (int i = 0; i < n; i++) {
    int p;
    cin >> p;
    cnt[p]++;
  }
  memset(dp, -1, sizeof dp);
  base = max(1, d - 244);
  cout << calc(d, d) << endl;
  return 0;
}
