#include <bits/stdc++.h>
using namespace std;
const int maxN = 3e4 + 11;
int a[maxN];
int dp[maxN][1000];
int used[maxN][1000];
int d;
int solve(int i, int j) {
  int x = j - (d - 800);
  if (i >= maxN || x >= 1000) return 0;
  if (used[i][x]) return dp[i][x];
  used[i][x] = 1;
  if (j == 1)
    dp[i][x] = a[i] + max(solve(i + j, j), solve(i + j + 1, j + 1));
  else
    dp[i][x] = a[i] + max(solve(i + j - 1, j - 1),
                          max(solve(i + j, j), solve(i + j + 1, j + 1)));
  return dp[i][x];
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n >> d;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    a[x]++;
  }
  cout << solve(d, d) << "\n";
  return 0;
}
