#include <bits/stdc++.h>
using namespace std;
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " =: " << a << "\n";
  err(++it, args...);
}
template <typename T1, typename T2>
inline std::ostream& operator<<(std::ostream& os, const std::pair<T1, T2>& p) {
  return os << "(" << p.first << ": " << p.second << ")";
}
template <typename T>
inline std::ostream& operator<<(std::ostream& os, const std::vector<T>& v) {
  bool first = true;
  os << "[";
  for (unsigned int i = 0; i < v.size(); i++) {
    if (!first) os << ", ";
    os << v[i];
    first = false;
  }
  return os << "]";
}
template <typename T>
inline std::ostream& operator<<(std::ostream& os, const std::set<T>& v) {
  bool first = true;
  os << "{";
  for (typename std::set<T>::const_iterator ii = v.begin(); ii != v.end();
       ++ii) {
    if (!first) os << ", ";
    os << *ii;
    first = false;
  }
  return os << "}";
}
template <typename T1, typename T2>
inline std::ostream& operator<<(std::ostream& os, const std::map<T1, T2>& v) {
  bool first = true;
  os << "{";
  for (typename std::map<T1, T2>::const_iterator ii = v.begin(); ii != v.end();
       ++ii) {
    if (!first) os << ", ";
    os << *ii;
    first = false;
  }
  return os << "}";
}
template <typename T>
inline std::ostream& operator<<(std::ostream& os,
                                const std::unordered_set<T>& v) {
  return os << std::set<T>(v.begin(), v.end());
}
template <typename T1, typename T2>
inline std::ostream& operator<<(std::ostream& os,
                                const std::unordered_map<T1, T2>& v) {
  return os << std::map<T1, T2>(v.begin(), v.end());
}
const long long int MOD = 1e9 + 7;
const long long int INF = 1e18;
const double EPS = 1e-6;
int main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL);
  long long int n, x, y, m, d;
  cin >> n >> d;
  vector<int> a(30001, 0);
  vector<int> dp(15030001, -1);
  for (int i = 0; i < n; ++i) cin >> x, a[x]++;
  function<int(int, int)> solve = [&](int cur, int dis) {
    if (dis <= 0 || cur > 30000) return 0;
    if (dp[cur * 500 + dis] != -1) return dp[cur * 500 + dis];
    int ret = 0;
    ret = max(ret, solve(cur + dis - 1, dis - 1));
    ret = max(ret, solve(cur + dis, dis));
    ret = max(ret, solve(cur + dis + 1, dis + 1));
    return dp[cur * 500 + dis] = ret + a[cur];
  };
  cout << solve(d, d);
  return 0;
}
