#include <bits/stdc++.h>
using namespace std;
void debug() { cout << endl; }
template <class FIRST, class... REST>
void debug(FIRST arg, REST... rest) {
  cout << arg << " ";
  debug(rest...);
}
template <class T>
void showary(T begin, T end) {
  while (begin != end) {
    cout << *begin << " ";
    begin++;
  }
  cout << endl;
}
int N, d;
int dp[30010][700];
int c[30100];
int main() {
  cin >> N >> d;
  for (int i = (0); i < (N); i++) {
    int a;
    cin >> a;
    c[a]++;
  }
  for (int i = (0); i < (30002); i++)
    for (int j = (0); j < (700); j++) dp[i][j] = -(1 << 28);
  dp[0][350] = 0;
  for (int i = (0); i < (30001); i++) {
    for (int j = (0); j < (700); j++) {
      if (dp[i][j] < 0) continue;
      if (i == 0)
        dp[min(i + d, 30001)][j] =
            max(dp[min(i + d, 30001)][j], dp[i][j] + c[i]);
      else {
        int v = d + j - 350;
        if (v - 1 >= 1)
          dp[min(i + v - 1, 30001)][j - 1] =
              max(dp[min(i + v - 1, 30001)][j - 1], dp[i][j] + c[i]);
        dp[min(i + v + 1, 30001)][j + 1] =
            max(dp[min(i + v + 1, 30001)][j + 1], dp[i][j] + c[i]);
        dp[min(i + v, 30001)][j] =
            max(dp[min(i + v, 30001)][j], dp[i][j] + c[i]);
      }
    }
  }
  int ans = 0;
  for (int i = (0); i < (700); i++) ans = max(ans, dp[30001][i]);
  cout << ans << endl;
}
