#include <bits/stdc++.h>
using namespace std;
long long dp[30001][500];
long long gems[30001];
long long n, d;
long long dfs(long long i, long long j) {
  long long off = (j - (d - 250));
  if (dp[i][off] != -1) return dp[i][off];
  long long res = 0;
  if ((i + j - 1) < 30001 && (j - 1) > 0) res = max(res, dfs(i + j - 1, j - 1));
  if ((i + j) < 30001) res = max(res, dfs(i + j, j));
  if ((i + j + 1) < 30001) res = max(res, dfs(i + j + 1, j + 1));
  return (dp[i][off] = res + gems[i]);
}
signed main() {
  ;
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(10);
  long long t = 1;
  while (t--) {
    memset(dp, -1, sizeof dp);
    memset(gems, 0, sizeof(gems));
    cin >> n >> d;
    long long x;
    for (long long i = 0; i < n; i++) {
      cin >> x;
      gems[x]++;
    }
    dfs(d, d);
    cout << dp[d][250];
  };
}
