#include <bits/stdc++.h>
const double eps = 1e-9;
const int mod = 1e9 + 7;
const int N = 30101;
int dx[] = {-1, -1, -1, 0, 0, 1, 1, 1};
int dy[] = {-1, 0, 1, -1, 1, -1, 0, 1};
long long gcd(long long x, long long y) { return (!y) ? x : gcd(y, x % y); }
long long lcm(long long x, long long y) { return ((x / gcd(x, y)) * y); }
using namespace std;
void fast() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}
int dp[N][651];
int n, d;
int fr[N];
int solve(int idx, int mm) {
  if (idx > 30000) return 0;
  int &ret = dp[idx][mm];
  if (~ret) return ret;
  ret = max(solve(idx + mm, mm), solve(idx + mm, mm + 1));
  if (mm > 1) ret = max(ret, solve(idx + mm, mm - 1));
  ret += fr[idx];
  return ret;
}
int main() {
  memset((dp), -1, sizeof(dp));
  int num;
  cin >> n >> d;
  while (n--) {
    cin >> num;
    fr[num]++;
  }
  cout << solve(0, d);
  return 0;
}
