#include <bits/stdc++.h>
using namespace std;
const int MAXN = 3e4 + 10, Z = 500;
int N, D;
int a[MAXN];
int f[MAXN][2 * Z];
int main() {
  scanf("%d%d", &N, &D);
  for (int i = 0, x; i < N; i++) {
    scanf("%d", &x);
    a[x]++;
  }
  for (int i = MAXN - 1; i >= 0; i--) {
    for (int l = 0; l < 2 * Z; l++) {
      f[i][l] = a[i];
      for (int d = -1; d <= 1; d++) {
        int j = i + D + l - Z + d;
        if (j > i && j < MAXN && l + d >= 0 && l + d < 2 * Z)
          f[i][l] = max(f[i][l], a[i] + f[j][l + d]);
      }
    }
  }
  printf("%d\n", f[D][Z]);
}
