#include <bits/stdc++.h>
using namespace std;
using namespace std;
class DisjointSet {
 public:
  vector<long long> parent;
  DisjointSet(long long n) : parent(n) {
    for (long long i = 0; i < n; i++) parent[i] = i;
  }
  void join(long long a, long long b) { parent[find(b)] = find(a); }
  long long find(long long a) {
    return a == parent[a] ? a : parent[a] = find(parent[a]);
  }
  bool check(long long a, long long b) { return find(a) == find(b); }
};
long long dp[30001][600];
vector<long long> arr(30001, 0);
long long n;
long long b;
long long solve(long long id, long long distortion) {
  if (300 + distortion > 599) cout << "Hello officer " << 1000 + distortion;
  if (id > n) return 0;
  if (dp[id][300 + distortion] != -1) return dp[id][300 + distortion];
  long long d1, d2, d3;
  d1 = b + distortion;
  d2 = b + distortion - 1;
  d3 = b + distortion + 1;
  long long a1 = 0, a2 = 0, a3 = 0;
  a1 = solve(id + d1, d1 - b);
  if (d2 != 0) a2 = solve(id + d2, d2 - b);
  a3 = solve(id + d3, d3 - b);
  return dp[id][300 + distortion] = arr[id] + max(a1, max(a2, a3));
}
int32_t main() {
  long long prevDistance, gems;
  cin >> gems >> prevDistance;
  for (long long i = 0; i < gems; ++i) {
    long long x;
    cin >> x;
    arr[x] += 1;
  }
  n = 30000;
  b = prevDistance;
  memset(dp, -1, sizeof(dp));
  solve(prevDistance, 0);
  cout << dp[prevDistance][300] << endl;
}
