#include <bits/stdc++.h>
using namespace std;
int n, d;
int p[30001];
int cache[30001][501];
int maxTreasure(int from, int jump) {
  if (jump <= 0) return 0;
  if (from > 30000) return 0;
  int jidx = jump - (d - 250);
  int& ret = cache[from][jidx];
  if (ret != -1) return ret;
  if (jump == 1) {
    ret = p[from] + max(maxTreasure(from + 1, 1), maxTreasure(from + 2, 2));
  } else {
    ret = p[from] + max(max(maxTreasure(from + jump - 1, jump - 1),
                            maxTreasure(from + jump, jump)),
                        maxTreasure(from + jump + 1, jump + 1));
  }
  return ret;
}
int main() {
  cin >> n >> d;
  memset(p, 0, sizeof(p));
  memset(cache, -1, sizeof(cache));
  for (int i = 0; i < n; i++) {
    int t;
    cin >> t;
    p[t]++;
  }
  cout << maxTreasure(d, d);
  return 0;
}
