#include <bits/stdc++.h>
using namespace std;
long long fastexpo(long long a, long long b) {
  long long res = 1;
  while (b > 0) {
    if (b % 2) res = ((res) % 1000000007 * (a) % 1000000007) % 1000000007;
    a = (a) % 1000000007 * (a) % 1000000007;
    b /= 2;
  }
  return res;
}
struct pair_hash {
  template <class T1, class T2>
  std::size_t operator()(const std::pair<T1, T2> &p) const {
    auto h1 = std::hash<T1>{}(p.first);
    auto h2 = std::hash<T2>{}(p.second);
    return 50000 * (h1 + 1) + h2;
  }
};
int n, d, dd;
vector<vector<int> > dp(30001, vector<int>(500, -1));
vector<int> check(30001, 0);
long long fans = 0;
int y;
long long rec(int i, int l) {
  if (i > y)
    return 0;
  else {
    int jj = l - (d - 250);
    if (dp[i][jj] == -1) {
      if (l != 1)
        dp[i][jj] = check[i] + max(rec(i + l, l), max(rec(i + l - 1, l - 1),
                                                      rec(i + l + 1, l + 1)));
      else
        dp[i][jj] = check[i] + rec(i + l, l);
      return dp[i][jj];
    } else
      return dp[i][jj];
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> n >> d;
  dd = ((d + 1) * (d)) / 2;
  for (int i = 0; i < n; i++) {
    cin >> y;
    check[y]++;
  }
  cout << rec(0 + d, d);
}
