#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pli = pair<ll, int>;
const int INF = 0x3f3f3f3f, N = 3e4 + 5, M = 550, offset = 250;
const ll LINF = 1e18 + 5;
int n, d, p[N], gem[N];
int dp[N][M];
int solve() {
  memset(dp, -1, sizeof(dp));
  dp[0][0] = 0;
  dp[d][offset] = gem[d];
  int ans = gem[d];
  for (int i = d; i <= p[n]; i++) {
    for (int j = max(1, d - offset); j <= d + offset; j++) {
      for (int k = max(1, j - 1); k <= j + 1; k++) {
        int pre = i - j;
        if (pre >= d && ~dp[pre][k - d + offset])
          dp[i][j - d + offset] =
              max(dp[i][j - d + offset], dp[pre][k - d + offset] + gem[i]);
      }
      ans = max(ans, dp[i][j - d + offset]);
    }
  }
  return ans;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> d;
  for (int i = 1; i <= n; i++) {
    cin >> p[i];
    gem[p[i]]++;
  }
  cout << solve();
  return 0;
}
