#include <bits/stdc++.h>
using namespace std;
int n, d, m, ar[2 * 30002];
int dp[30002][2005];
int go(int pos, int gp) {
  if (pos > m) return 0;
  int &ret = dp[pos][gp];
  if (ret != -1) return ret;
  ret = 0;
  if (pos + gp - 1 > pos)
    ret = max(ret, ar[pos + gp - 1] + go(pos + gp - 1, gp - 1));
  if (pos + gp > pos) ret = max(ret, ar[pos + gp] + go(pos + gp, gp));
  if (pos + gp + 1 > pos)
    ret = max(ret, ar[pos + gp + 1] + go(pos + gp + 1, gp + 1));
  return ret;
}
int go2(int pos, int gp) {
  if (pos > m) return 0;
  int ret = 0;
  if (pos + gp - 1 > pos)
    ret = max(ret, ar[pos + gp - 1] + go2(pos + gp - 1, gp - 1));
  if (pos + gp > pos) ret = max(ret, ar[pos + gp] + go2(pos + gp, gp));
  if (pos + gp + 1 > pos)
    ret = max(ret, ar[pos + gp + 1] + go2(pos + gp + 1, gp + 1));
  return ret;
}
int main() {
  int tc, cs = 1, x, i, j, k;
  ios_base::sync_with_stdio(0), cin.tie(0);
  while (cin >> n >> d) {
    memset(ar, 0, sizeof(ar));
    for (i = 1; i <= n; i++) {
      cin >> x;
      ar[x]++;
      m = max(m, x);
    }
    memset(dp, -1, sizeof(dp));
    long long ans;
    if (d <= 2000)
      ans = ar[d] + go(d, d);
    else
      ans = ar[d] + go2(d, d);
    cout << ans << endl;
  }
  return 0;
}
