#include <bits/stdc++.h>
using namespace std;
int n, d, dp[31000][500], mx, rang, m[31000];
int solve(int a, int b) {
  if (a > rang) return 0;
  int ret = dp[a][b];
  if (ret != -1) return ret;
  if (b > 1) {
    dp[a][b] = max(dp[a][b], solve(a + b - 1, b - 1) + m[a]);
  }
  dp[a][b] = max(dp[a][b], solve(a + b + 1, b + 1) + m[a]);
  dp[a][b] = max(dp[a][b], solve(a + b, b) + m[a]);
  mx = max(mx, dp[a][b]);
  return dp[a][b];
}
int main() {
  cin >> n >> d;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    m[x]++;
    rang = max(rang, x);
  }
  memset(dp, -1, sizeof(dp));
  solve(d, d);
  cout << mx << endl;
}
