#include <bits/stdc++.h>
using namespace std;
const int N = 31005;
int dp[N][500], rg, num[N], ans;
int dfs(int x, int l) {
  if (x > rg) return 0;
  if (dp[x][l] != -1) return dp[x][l];
  if (l >= 2) dp[x][l] = max(dp[x][l], dfs(x + l - 1, l - 1)) + num[x];
  dp[x][l] = max(dp[x][l], dfs(x + l, l) + num[x]);
  dp[x][l] = max(dp[x][l], dfs(x + l + 1, l + 1) + num[x]);
  ans = max(ans, dp[x][l]);
  return dp[x][l];
}
int main() {
  int n, d;
  scanf("%d %d", &n, &d);
  for (int i = 1; i <= n; i++) {
    int k;
    scanf("%d", &k);
    num[k]++;
    rg = max(rg, k);
  }
  memset(dp, -1, sizeof dp);
  dfs(d, d);
  printf("%d\n", ans);
  return 0;
}
