#include <bits/stdc++.h>
using namespace std;
const int BASE = 250;
int N, D;
int A[30002], is[30002];
int MAX[30002][502], result;
void maximize(int& now, int aux) {
  now = max(now, aux);
  result = max(result, now);
}
int main() {
  cin.sync_with_stdio(false);
  cin >> N >> D;
  for (int i = 1; i <= N; ++i) {
    cin >> A[i];
    ++is[A[i]];
  }
  memset(MAX, -1, sizeof(MAX));
  MAX[D][BASE] = is[D];
  result = is[D];
  for (int i = D; i <= 30000; ++i)
    for (int j = 0; j <= 500; ++j)
      if (MAX[i][j] != -1) {
        if (i + D + (j - BASE) - 1 > i && i + D + (j - BASE) - 1 <= 30000)
          maximize(MAX[i + D + (j - BASE) - 1][j - 1],
                   MAX[i][j] + is[i + D + (j - BASE) - 1]);
        if (i + D + (j - BASE) > i && i + D + (j - BASE) <= 30000)
          maximize(MAX[i + D + (j - BASE)][j],
                   MAX[i][j] + is[i + D + (j - BASE)]);
        if (i + D + (j - BASE) + 1 > i && i + D + (j - BASE) + 1 <= 30000)
          maximize(MAX[i + D + (j - BASE) + 1][j + 1],
                   MAX[i][j] + is[i + D + (j - BASE) + 1]);
      }
  cout << result << '\n';
}
