#include <bits/stdc++.h>
using namespace std;
void smain();
int main() {
  ios_base::sync_with_stdio(0);
  smain();
  return 0;
}
long long n, m, L, p[30003], ps[30003];
long long d[30003][500];
map<long long, long long> md[30003];
inline void update(long long j, long long l, long long v) {
  if (l < 500) {
    d[j][l] = max(d[j][l], v);
  } else {
    if (md[j].count(l) == 0)
      md[j].insert(make_pair(l, v));
    else if (md[j].at(l) < v)
      md[j].at(l) = v;
  }
}
void smain() {
  for (long long t = 0; cin >> n >> L; ++t) {
    memset(d, 255, sizeof(d));
    m = 0;
    for (long long i = 0; i < n; i++) {
      long long v;
      cin >> v;
      p[v] += 1;
      m = max(v, m);
    }
    for (long long i = m + 1 - 1; i >= 0; i--) ps[i] = ps[i + 1] + p[i];
    update(L, L, 0);
    long long res = 0;
    for (long long i = L; i <= m; ++i) {
      for (long long j = 0; j < 500; j++)
        if (d[i][j] != -1) {
          long long l = j;
          if (l <= 2) {
            res = max(res, d[i][j] + ps[i]);
            continue;
          } else {
            long long v = d[i][j] + p[i];
            res = max(res, d[i][j] + p[i]);
            if (i + l - 1 <= m) update(i + l - 1, l - 1, v);
            if (i + l <= m) update(i + l, l, v);
            if (i + l + 1 <= m) update(i + l + 1, l + 1, v);
          }
        }
      for (auto it = md[i].begin(); it != md[i].end(); ++it) {
        long long l = it->first;
        if (l <= 2) {
          res = max(res, it->second + ps[i]);
          continue;
        } else {
          res = max(res, it->second + p[i]);
          if (i + l - 1 <= m) update(i + l - 1, l - 1, it->second + p[i]);
          if (i + l <= m) update(i + l, l, it->second + p[i]);
          if (i + l + 1 <= m) update(i + l + 1, l + 1, it->second + p[i]);
        }
      }
    }
    cout << res << '\n';
  }
}
