#include <bits/stdc++.h>
using namespace std;
int n, d;
set<int> ansSet;
map<pair<int, int>, int> ansMap;
int posNstep[30000 + 1][1000];
int gems[30000 + 1];
int threeMax(int a, int b, int c) { return max(max(a, b), c); }
int dfsSavingAnswers(int position, int stepSize) {
  if (position > 30000) {
    return 0;
  }
  pair<int, int> cur = {position, stepSize};
  if (ansMap.count(cur) != 0) {
    return ansMap[cur];
  }
  if (stepSize == 1) {
    ansMap[cur] = max(dfsSavingAnswers(position + stepSize + 1, stepSize + 1),
                      dfsSavingAnswers(position + stepSize, stepSize)) +
                  gems[position];
    return ansMap[cur];
  } else {
    ansMap[cur] =
        threeMax(dfsSavingAnswers(position + stepSize + 1, stepSize + 1),
                 dfsSavingAnswers(position + stepSize, stepSize),
                 dfsSavingAnswers(position + stepSize - 1, stepSize - 1)) +
        gems[position];
    return ansMap[cur];
  }
}
void arrayInit() {
  for (int i = 0; i <= 30000; i++)
    for (int j = 1; j < 1000; j++) posNstep[i][j] = -7;
}
int dfsOnArray(int position, int stepSize) {
  if (position > 30000) return 0;
  if (posNstep[position][stepSize] != -7) return posNstep[position][stepSize];
  if (stepSize == 1) {
    posNstep[position][stepSize] =
        max(dfsOnArray(position + stepSize + 1, stepSize + 1),
            dfsOnArray(position + stepSize, stepSize)) +
        gems[position];
    return posNstep[position][stepSize];
  } else {
    posNstep[position][stepSize] =
        threeMax(dfsOnArray(position + stepSize + 1, stepSize + 1),
                 dfsOnArray(position + stepSize, stepSize),
                 dfsOnArray(position + stepSize - 1, stepSize - 1)) +
        gems[position];
    return posNstep[position][stepSize];
  }
}
int main() {
  cin >> n >> d;
  for (int i = 0; i < n; i++) {
    int islandNum;
    cin >> islandNum;
    gems[islandNum]++;
  }
  if (d >= 900) {
    cout << dfsSavingAnswers(d, d) << endl;
    return 0;
  }
  arrayInit();
  cout << dfsOnArray(d, d) << endl;
}
