#include <bits/stdc++.h>
const int ZERO = 250;
const int MAX_N = 30000;
int f[MAX_N + 5][ZERO * 2];
int gems[MAX_N + 5];
int main() {
  int n, d, m;
  scanf("%d%d", &n, &d);
  for (int i = 0; i < n; i++) {
    scanf("%d", &m);
    gems[m]++;
  }
  memset(f, 0xff, sizeof(f));
  f[d][ZERO] = gems[d];
  int ans = 0;
  for (int i = d; i <= m; i++) {
    for (int j = 1; j < ZERO * 2; j++) {
      if (f[i][j] < 0) continue;
      if (f[i][j] > ans) ans = f[i][j];
      for (int k = j - 1; k <= j + 1; k++) {
        int next_i = i + k - ZERO + d;
        if (next_i > i && next_i <= m &&
            f[i][j] + gems[next_i] > f[next_i][k]) {
          f[next_i][k] = f[i][j] + gems[next_i];
        }
      }
    }
  }
  printf("%d\n", ans);
  return 0;
}
