#include <bits/stdc++.h>
int dp[30005][505];
int n, d, p, num[30005];
int dfs(int now, int l) {
  int j = l - d + 250;
  if (now == p) return dp[now][j] = num[p];
  if (dp[now][j] != -1) return dp[now][j];
  int ans = 0;
  if (l > 1 && now + l - 1 <= p) ans = std::max(ans, dfs(now + l - 1, l - 1));
  if (now + l <= p) ans = std::max(ans, dfs(now + l, l));
  if (now + l + 1 <= p) ans = std::max(ans, dfs(now + l + 1, l + 1));
  return dp[now][j] = ans + num[now];
}
int main() {
  while (~scanf("%d%d", &n, &d)) {
    memset(dp, -1, sizeof dp);
    memset(num, 0, sizeof num);
    for (int i = 0; i < n; i++) {
      scanf("%d", &p);
      num[p]++;
    }
    printf("%d\n", dfs(d, d));
  }
  return 0;
}
