#include <bits/stdc++.h>
using namespace std;
int g[30005], ans = 0, mx = 0, dp[30005][500], d;
int dfs(int x, int l) {
  if (dp[x][l] + 1) return dp[x][l];
  int cnt = 0;
  for (int i = -1; i < 2; i++) {
    if (d + l + i < 1 || x + d + l + i > mx) continue;
    cnt = max(cnt, dfs(l + i + d + x, l + i));
  }
  return dp[x][l] = cnt + g[x];
}
int main() {
  int n;
  scanf("%d %d", &n, &d);
  for (int i = 0; i < n; i++) {
    int x;
    scanf("%d", &x);
    g[x]++;
    mx = max(mx, x);
  }
  memset(dp, -1, sizeof(dp));
  printf("%d", dfs(d, 0));
  return 0;
}
