#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const long double pi = 3.14159265358979323846264338327950288419716939937510;
long long po(long long a, long long b) {
  long long res = 1 % mod;
  a %= mod;
  for (; b; b >>= 1) {
    if (b & (1LL)) res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
const long double eps = 1e-10;
const int oo = 1000000009;
const long long ooo = 2e18 + 5;
int DP[30009][509];
int cntGen[30009];
int mx;
int d;
int Go(int curr, int len) {
  if (curr > 30000) return 0;
  if (DP[curr][len - d + 250] != -1) return DP[curr][len - d + 250];
  int ret = 0;
  if (len - 1 > 0) ret = Go(curr + len - 1, len - 1);
  ret = max(ret, Go(curr + len, len));
  ret = max(ret, Go(curr + len + 1, len + 1));
  DP[curr][len - d + 250] = ret + cntGen[curr];
  return ret + cntGen[curr];
}
int main() {
  int n, a;
  scanf("%d %d", &n, &d);
  memset(cntGen, 0, sizeof(cntGen));
  memset(DP, -1, sizeof(DP));
  mx = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a);
    cntGen[a]++;
  }
  cout << Go(d, d) << endl;
  return 0;
}
