#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using pii = pair<int, int>;
const int INF = 2147483647;
int best[30005][1000];
int gems[30005];
int offset;
int findbest(int from, int d) {
  if (-1 != best[from][d - offset]) return best[from][d - offset];
  int re = gems[from];
  for (int i = int(-1); i < int(2); ++i) {
    if (d + i <= 0) continue;
    if (from + d + i <= 30000) {
      re = max(re, gems[from] + findbest(from + d + i, d + i));
    }
  }
  best[from][d - offset] = re;
  return re;
}
int main() {
  memset(gems, 0, sizeof(gems));
  memset(best, -1, sizeof(best));
  int n, d;
  cin >> n >> d;
  for (int i = 0; i < int(n); ++i) {
    int p_i;
    cin >> p_i;
    gems[p_i]++;
  }
  offset = d - 500;
  printf("%d\n", findbest(d, d));
  return 0;
}
