#include <bits/stdc++.h>
using namespace std;
int dp[30005][1000];
int d, n, maxn;
int a[30005];
int dfs(int p, int pre) {
  if (p > maxn) return 0;
  if (dp[p][pre - d + 300] > -1) return dp[p][pre - d + 300];
  int res = 0;
  if (pre > 1) res = max(res, dfs(p + pre - 1, pre - 1));
  res = max(res, dfs(p + pre, pre));
  res = max(res, dfs(p + pre + 1, pre + 1));
  return dp[p][pre - d + 300] = res + a[p];
}
int main() {
  memset(dp, -1, sizeof(dp));
  memset(a, 0, sizeof(a));
  scanf("%d %d", &n, &d);
  maxn = -1;
  for (int i = 1; i <= n; i++) {
    int x;
    scanf("%d", &x);
    maxn = max(maxn, x);
    a[x]++;
  }
  printf("%d\n", dfs(d, d));
  return 0;
}
