#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e4 + 5;
const int maxk = 505;
int N, d;
int dp[maxn][maxk], gem[maxn], vis[maxn][maxk];
int dfs(int pos, int prev) {
  int jj = prev - (d - 250);
  if (pos > 30000) return 0;
  if (vis[pos][jj]) return dp[pos][jj];
  vis[pos][jj] = 1;
  int ans = 0;
  if (prev == 1)
    ans = max(ans, max(dfs(pos + 1, 1), dfs(pos + 2, 2)));
  else
    ans = max(ans,
              max(dfs(pos + prev - 1, prev - 1),
                  max(dfs(pos + prev, prev), dfs(pos + prev + 1, prev + 1))));
  return dp[pos][jj] = ans + gem[pos];
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> N >> d;
  for (int i = 1; i <= N; i++) {
    int p;
    cin >> p;
    gem[p]++;
  }
  cout << dfs(d, d) << "\n";
  return 0;
}
