#include <bits/stdc++.h>
using namespace std;
const int inft = 1000000009;
const int MAXN = 30006;
int ile[MAXN];
vector<pair<int, int> > V[MAXN];
int main() {
  int n, d;
  scanf("%d%d", &n, &d);
  for (int i = 0; i < (n); ++i) {
    int a;
    scanf("%d", &a);
    ++ile[a];
  }
  V[d].push_back(pair<int, int>(d, ile[d]));
  int ret = 0;
  for (int i = 0; i < (MAXN); ++i) {
    sort((V[i]).begin(), (V[i]).end());
    for (int j = 0; j < (V[i].size()); ++j)
      if (j + 1 == V[i].size() || V[i][j].first != V[i][j + 1].first) {
        for (int k = 0; k < (3); ++k) {
          int sk = V[i][j].first + k - 1;
          if (sk == 0) continue;
          int ne = i + sk;
          if (ne < MAXN)
            V[ne].push_back(pair<int, int>(sk, V[i][j].second + ile[ne]));
        }
      }
    for (typeof((V[i]).begin()) it = (V[i]).begin(); it != (V[i]).end(); ++it)
      ret = max(ret, it->second);
    vector<pair<int, int> > E;
    swap(E, V[i]);
  }
  printf("%d\n", ret);
  return 0;
}
