#include <bits/stdc++.h>
using namespace std;
int n, dd;
int a[30001];
int b[30001][1200];
int ma;
int f(int x, int d) {
  if (b[x][d] != -1) return b[x][d];
  int ret = 0;
  for (int i = -1; i <= 1; i++) {
    if (x + d + dd - 600 + i <= ma && i + dd + d - 600 > 0) {
      ret = max(ret, f(x + d - 600 + dd + i, d + i));
    }
  }
  return b[x][d] = ret + a[x];
}
void solve() {
  memset(a, 0, sizeof(a));
  memset(b, 0xff, sizeof(b));
  int t;
  for (int i = 0; i < n; i++) {
    scanf("%d", &t);
    a[t]++;
  }
  ma = t;
  printf("%d\n", f(dd, 600));
}
int main() {
  int t;
  while (~scanf("%d%d", &n, &dd)) {
    solve();
  }
  return 0;
}
