#include <bits/stdc++.h>
using namespace std;
void init() {
  cin.tie(0);
  cin.sync_with_stdio(0);
  cout.tie(0);
}
long long second(long long x) {
  long long s = 0;
  while (x) {
    s += x % 10;
    x /= 10;
  }
  return s;
}
long long powe(long long a, long long n) {
  if (n == 1) return a;
  return a * powe(a, n - 1);
}
long long com(int n, int m) {
  long long z = 1;
  for (int i = 0; i < m; i++) {
    z = z * (n - i) / (i + 1);
  }
  return z;
}
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
int dr[] = {0, 0, 0, 1, 1, 1, -1, -1, -1};
int dc[] = {-1, 0, 1, -1, 0, 1, -1, 0, 1};
int n, d;
int arr[30007];
int dp[30007][505];
int solve(int i, int lst) {
  if (i > 30001) return 0;
  int pos = lst - (d - 250);
  int &rst = dp[i][pos];
  if (~rst) return rst;
  rst = 0;
  rst = solve(i + lst, lst);
  rst = max(rst, solve(i + lst + 1, lst + 1));
  if (lst != 1) rst = max(rst, solve(i + lst - 1, lst - 1));
  return rst += arr[i];
}
int main() {
  init();
  cin >> n >> d;
  memset(dp, -1, sizeof(dp));
  for (int i = 0; i < n; i++) {
    int ipt;
    cin >> ipt;
    arr[ipt]++;
  }
  cout << solve(d, d);
}
