#include <bits/stdc++.h>
using namespace std;
const long long M = 30001;
long long a[30001], f[30001][700], n, d;
bool used[30001][501];
long long solve(long long x, long long y) {
  long long j = y - (d - 250);
  if (x >= M) return 0;
  if (used[x][j]) return f[x][j];
  used[x][j] = true;
  long long res;
  if (y == 1) {
    res = a[x] + max(solve(x + y, y), solve(x + y + 1, y + 1));
  } else
    res = a[x] + max(max(solve(x + y, y), solve(x + y + 1, y + 1)),
                     solve(x + y - 1, y - 1));
  f[x][j] = res;
  return res;
}
void input() {
  cin >> n >> d;
  long long fi = 0;
  for (int i = 1; i <= n; ++i) {
    long long x;
    cin >> x;
    ++a[x];
  }
  cout << solve(d, d);
}
int main() {
  ios_base::sync_with_stdio(false);
  input();
}
