#include <bits/stdc++.h>
using namespace std;
const int maxint = -1u >> 1;
template <class T>
bool get_max(T& a, const T& b) {
  return b > a ? a = b, 1 : 0;
}
template <class T>
bool get_min(T& a, const T& b) {
  return b < a ? a = b, 1 : 0;
}
const int maxn = 30005;
const int maxs = 300;
int n, d, p[maxn];
int dp[maxn][maxs << 1];
int main() {
  scanf("%d%d", &n, &d);
  for (int i = 0; i < n; i++) {
    int v;
    scanf("%d", &v);
    p[v]++;
  }
  memset(dp, -1, sizeof(dp));
  dp[d][maxs] = p[d];
  int ans = -1;
  for (int i = d; i <= 30000; i++) {
    for (int j = -maxs; j <= maxs; j++) {
      int t = dp[i][j + maxs];
      if (t == -1) continue;
      get_max(ans, t);
      for (int k = -1; k <= 1; k++) {
        int l = i + d + j + k;
        if (l <= 0 || l > 30000) continue;
        get_max(dp[l][j + k + maxs], dp[i][j + maxs] + p[l]);
      }
    }
  }
  printf("%d\n", ans);
  return 0;
}
