#include <bits/stdc++.h>
using namespace std;
int n, m, D[30001][1000], i, j, d, MAX, MAX2, x, a[30001];
int main() {
  cin >> n >> d;
  for (i = 1; i <= n; i++) {
    cin >> x;
    if (x > MAX) MAX = x;
    a[x]++;
  }
  j = d;
  for (i = 0; i <= 30000; i++)
    for (j = 0; j <= 1000; j++) D[i][j] = -1;
  D[d][500] = a[d];
  for (i = d; i <= 30000; i++)
    for (j = 0; j <= 1000; j++) {
      int pr = d + j - 500;
      if (pr <= 0 || pr > i) continue;
      if (j)
        if (D[i - pr][j - 1] != -1) D[i][j] = D[i - pr][j - 1] + a[i];
      if (D[i - pr][j] != -1) D[i][j] = max(D[i - pr][j] + a[i], D[i][j]);
      if (j + 1 <= 1000)
        if (D[i - pr][j + 1] != -1)
          D[i][j] = max(D[i][j], D[i - pr][j + 1] + a[i]);
      MAX2 = max(MAX2, D[i][j]);
    }
  cout << MAX2;
  return 0;
}
