#include <bits/stdc++.h>
using namespace std;
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &t) {
  os << "[";
  for (__typeof((t).begin()) it = (t).begin(); it != (t).end(); it++) {
    if (it != t.begin()) os << ",";
    os << *it;
  }
  os << "]";
  return os;
}
template <class T>
ostream &operator<<(ostream &os, const set<T> &t) {
  os << "{";
  for (__typeof((t).begin()) it = (t).begin(); it != (t).end(); it++) {
    if (it != t.begin()) os << ",";
    os << *it;
  }
  os << "}";
  return os;
}
template <class S, class T>
ostream &operator<<(ostream &os, const pair<S, T> &t) {
  return os << "(" << t.first << "," << t.second << ")";
}
template <class S, class T>
pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) {
  return pair<S, T>(s.first + t.first, s.second + t.second);
}
template <class S, class T>
pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) {
  return pair<S, T>(s.first - t.first, s.second - t.second);
}
const int INF = 1 << 28;
const double EPS = 1e-8;
const int MOD = 1000000007;
int n, d;
int one[30001];
int gem[30001];
unordered_map<int, int> dp[30001];
int ans = 0;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  memset(one, -1, sizeof(one));
  scanf("%d%d", &n, &d);
  for (int i = 0; i < (int)(n); i++) {
    int x;
    scanf("%d", &x);
    gem[x]++;
  }
  dp[d][d] = gem[d];
  for (int i = 1; i <= (int)(30000); i++) {
    int minimum = (dp[i].find(1) == dp[i].end()) ? -1 : dp[i][1];
    for (__typeof((dp[i]).begin()) it = (dp[i]).begin(); it != (dp[i]).end();
         it++)
      if ((it->first == 1 && it->second >= 0) || it->second > minimum) {
        for (int q = -1; q <= 1; q++) {
          int nd = it->first + q;
          int ns = it->second + gem[i + nd];
          if (nd >= 1 && i + nd <= 30000) chmax(dp[i + nd][nd], ns);
        }
        ans = max(ans, it->second);
      }
  }
  cout << ans << endl;
  return 0;
}
