#include <bits/stdc++.h>
using namespace std;
const int N = 30005;
int dp[N][505], n, d, x, ans, cnt[N];
int f(int i, int j) {
  int steps = j + (250 - d);
  if (i >= N) return 0;
  if (dp[i][steps] != -1) return dp[i][steps];
  int res;
  res = cnt[i] + max(f(i + j + 1, j + 1), f(i + j, j));
  if (j > 1) {
    res = max(cnt[i] + f(i + j - 1, j - 1), res);
  }
  dp[i][steps] = res;
  return res;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> d;
  for (int i = 0; i < n; i++) {
    cin >> x;
    cnt[x]++;
  }
  memset(dp, -1, sizeof(dp));
  cout << f(d, d);
}
