#include <bits/stdc++.h>
using namespace std;
const int mod = 99999997;
const int mmax = 200010;
const double eps = 1e-8;
const double pi = acos(-1.0);
const int inf = 0x3fffffff;
int num[30010];
int Ha[10000010];
int dp[10000010];
int sum[30010];
int max_d;
int Hash(int pos, int len) {
  int m = pos + len * 30001;
  int p = m % 10000007;
  while (Ha[p] != -1) {
    if (Ha[p] == m) return p;
    p++;
    p %= 10000007;
  }
  Ha[p] = m;
  return p;
}
int dfs(int pos, int len) {
  int ans = 0;
  int hh = Hash(pos, len);
  if (dp[hh] != -1) return dp[hh];
  if (pos > max_d) return 0;
  if (len <= 2) return dp[hh] = sum[max_d] - sum[pos] + num[pos];
  if (len > 1) ans = max(ans, num[pos] + dfs(pos + len - 1, len - 1));
  ans = max(ans, num[pos] + dfs(pos + len, len));
  ans = max(ans, num[pos] + dfs(pos + len + 1, len + 1));
  return dp[hh] = ans;
}
int main() {
  int n, d;
  while (cin >> n >> d) {
    memset(Ha, -1, sizeof Ha);
    memset(num, 0, sizeof num);
    memset(dp, -1, sizeof dp);
    max_d = 0;
    for (int i = 0; i < n; i++) {
      int x;
      scanf("%d", &x);
      num[x]++;
      max_d = max(max_d, x);
    }
    sum[0] = 0;
    for (int i = 1; i <= max_d; i++) sum[i] = sum[i - 1] + num[i];
    cout << dfs(d, d) << endl;
  }
  return 0;
}
