#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e4;
const int maxm = 300;
int n, d;
int sum[maxn + 1];
int dp[maxn + 1][maxm << 1];
int dfs(int pos, int l) {
  if (~dp[pos][l + maxm]) return dp[pos][l + maxm];
  if (pos == 3e4) return sum[pos];
  dp[pos][l + maxm] = 0;
  if (d + l > 1 && pos + d + l - 1 <= maxn) {
    dp[pos][l + maxm] = max(dp[pos][l + maxm], dfs(pos + d + l - 1, l - 1));
  }
  if (pos + d + l <= maxn) {
    dp[pos][l + maxm] = max(dp[pos][l + maxm], dfs(pos + d + l, l));
  }
  if (pos + d + l + 1 <= maxn) {
    dp[pos][l + maxm] = max(dp[pos][l + maxm], dfs(pos + d + l + 1, l + 1));
  }
  dp[pos][l + maxm] += sum[pos];
  return dp[pos][l + maxm];
}
int main() {
  scanf("%d%d", &n, &d);
  for (int i = 1, p; i <= n; i++) {
    scanf("%d", &p);
    sum[p]++;
  }
  memset(dp, -1, sizeof dp);
  printf("%d\n", dfs(d, 0));
  return 0;
}
