#include <bits/stdc++.h>
using namespace std;
const long long INF = 2e9;
const long long MOD = 1e9 + 7;
vector<vector<long long>> dp;
vector<long long> good;
long long d;
long long rec(long long pos, long long now) {
  if (dp[now][pos] != -1) return dp[now][pos];
  long long res = 0;
  for (long long i = -1; i <= 1; i++) {
    if (now + i >= 0 && now + i < 500 &&
        pos + now - 249 + i + d < good.size() && now - 249 + i + d != 0)
      res = max(rec(pos + now - 249 + i + d, now + i), res);
  }
  res += good[pos];
  dp[now][pos] = res;
  return res;
}
void solve() {
  long long n;
  cin >> n >> d;
  good.resize(30001);
  for (long long i = 0; i < n; i++) {
    long long x;
    cin >> x;
    good[x]++;
  }
  dp.resize(500, vector<long long>(good.size(), -1));
  cout << rec(d, 249);
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cout.precision(12);
  solve();
}
