#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const long long High = 1e16;
void ControlIO();
void TimerStart();
void TimerStop();
template <typename Arg1>
void ZZ(const char *name, Arg1 &&arg1) {
  std::cerr << name << " = " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void ZZ(const char *names, Arg1 &&arg1, Args &&...args) {
  const char *comma = strchr(names + 1, ',');
  std::cerr.write(names, comma - names) << " = " << arg1;
  ZZ(comma, args...);
}
int n, d;
vector<int> V(30005);
vector<vector<int>> DP_Table(30005, vector<int>(1600, -1));
int rang = 0;
int Brute_Force(int i, int d) {
  if (i > rang) return 0;
  int ans = V[i];
  if (d > 1) ans = max(ans, V[i] + Brute_Force(i + d - 1, d - 1));
  ans = max(ans, V[i] + Brute_Force(i + d, d));
  ans = max(ans, V[i] + Brute_Force(i + d + 1, d + 1));
  return ans;
}
int DP(int i, int d) {
  if (i > rang) return 0;
  if (d >= 1500) return Brute_Force(i, d);
  int &ans = DP_Table[i][d];
  if (ans != -1) return ans;
  ans = V[i];
  if (d > 1) ans = max(ans, V[i] + DP(i + d - 1, d - 1));
  ans = max(ans, V[i] + DP(i + d, d));
  ans = max(ans, V[i] + DP(i + d + 1, d + 1));
  return ans;
}
void solve() {
  cin >> n >> d;
  int u;
  for (int i = 0; i < n; ++i) {
    cin >> u;
    V[u]++;
    rang = max(rang, u);
  }
  cout << DP(d, d);
}
int main() {
  ControlIO();
  int t = 1;
  TimerStart();
  while (t--) solve();
  TimerStop();
  return 0;
}
void ControlIO() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
}
auto TimeStart = chrono::steady_clock::now();
auto TimeEnd = chrono::steady_clock::now();
void TimerStart() {}
void TimerStop() {}
