#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e4 + 5;
int f[maxn][605], v[maxn];
int main() {
  int n, k, x;
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &x);
    v[x]++;
  }
  int s = 300;
  s <<= 1;
  n = 3e4;
  for (int i = k; i <= n; i++) {
    for (int j = 0; j <= s; j++) {
      f[i][j] = -1;
    }
  }
  f[k][300] = v[0] + v[k];
  int ans = 0;
  for (int i = k; i <= n; i++) {
    for (int j = 0; j <= s; j++) {
      if (f[i][j] == -1) continue;
      for (int c = -1; c < 2; c++) {
        int go = j + k + c - 300;
        if (i + go > n || j + c < 0 || j + c > s || go < 1) continue;
        go += i;
        f[go][j + c] = max(f[go][j + c], f[i][j] + v[go]);
      }
      ans = max(f[i][j], ans);
    }
  }
  printf("%d\n", ans);
  return 0;
}
