#include <bits/stdc++.h>
using namespace std;
const int n = 30005;
const int m = 505;
int N, D;
int cnt[n];
int dp[n][m], mx;
int go(int idx, int last) {
  if (idx > mx) return 0;
  int bound = last - D + 250;
  if (dp[idx][bound] != -1) return dp[idx][bound];
  int best = 0;
  best = max(best, go(idx + last + 1, last + 1));
  if (last - 1 > 0) best = max(best, go(idx + last - 1, last - 1));
  if (last > 0) best = max(best, go(idx + last + 0, last + 0));
  return dp[idx][bound] = cnt[idx] + best;
}
int main() {
  scanf("%d%d", &N, &D);
  for (int i = 1; i <= N; i++) {
    int x;
    scanf("%d", &x);
    cnt[x]++;
    mx = max(mx, x);
  }
  memset(dp, -1, sizeof dp);
  printf("%d\n", go(D, D));
}
