#include <bits/stdc++.h>
using namespace std;
int n, x, d;
int gem[30002], sum[30002];
int dp[30002][2001];
int func(int i, int l) {
  if (i > x || l == 0) return 0;
  if (l == 1 || l == 2) return sum[i];
  if (dp[i][l] != -1 && l <= 2000) return dp[i][l];
  int ret1 = 0, ret2 = 0, ret3 = 0;
  if (l > 1) ret3 = gem[i] + func(i + l - 1, l - 1);
  ret1 = gem[i] + func(i + l + 1, l + 1);
  ret2 = gem[i] + func(i + l, l);
  ret1 = max(ret1, ret2);
  if (l <= 2000) dp[i][l] = max(ret1, ret3);
  return max(ret1, ret3);
}
int main() {
  std::ios::sync_with_stdio(false);
  int i, j, ans, ad = 0;
  cin >> n >> d;
  for (i = 0; i <= 30000; i++) {
    gem[i] = sum[i] = 0;
  }
  for (i = 1; i <= n; i++) {
    cin >> x;
    gem[x]++;
  }
  ad = gem[x];
  sum[x] = gem[x];
  for (i = x - 1; i >= 0; i--) {
    ad += gem[i];
    sum[i] = ad;
  }
  for (i = 1; i <= 30000; i++) {
    for (j = 1; j <= 2000; j++) dp[i][j] = -1;
  }
  ans = func(d, d);
  cout << ans;
}
