#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std;
const int MAXLEN = 30000;
const int SQRT_LEN = 600;
const int MAGIC = SQRT_LEN * 2 + 10;
int gemCount[MAXLEN + 1];
unordered_map<int, int> dp;
int cache[MAXLEN + 1][MAGIC];
int go(int i, int d) {
  if (i > 30000) return 0;
  if (d < SQRT_LEN) return cache[i][d];
  int state = (i << 15) + d;
  const auto &pos = dp.find(state);
  if (pos != dp.end()) return pos->second;
  int &ans = dp[state];
  for (int j = d - 1; j <= d + 1; j++) {
    if (j > 0) {
      ans = max(ans, go(i + j, j));
    }
  }
  ans += gemCount[i];
  return ans;
}
int main() {
  int n, d;
  scanf("%d%d", &n, &d);
  for (int i = 0; i < n; i++) {
    int pos;
    scanf("%d", &pos);
    gemCount[pos]++;
  }
  for (int i = MAXLEN; i >= 0; i--) {
    for (int j = 1; j < MAGIC; j++) {
      for (int step = j - 1; step <= j + 1 && step < MAGIC; step++) {
        if (step > 0 && i + step <= MAXLEN) {
          cache[i][j] = max(cache[i + step][step], cache[i][j]);
        }
      }
      cache[i][j] += gemCount[i];
    }
  }
  cout << go(d, d) << endl;
  return 0;
}
