#include <bits/stdc++.h>
using namespace std;
const int M = 30000;
int z[M + 1];
int z1[M + 1];
int D;
template <class T>
struct ullHash {
  unsigned long long *key;
  T *val;
  unsigned memory, size, mask;
  void clear() { memset(val, 0, size * sizeof(T)); }
  void clear(int sz) {
    size = 1;
    while (size < sz) size *= 2;
    mask = size - 1;
    clear();
  }
  void init(int mem, int sz) {
    memory = mem;
    size = 1;
    while (size < sz) size *= 2;
    mask = size - 1;
    if (memory < size) memory = size;
    key = (unsigned long long *)malloc(memory * sizeof(unsigned long long));
    val = (T *)malloc(memory * sizeof(T));
    if (size) clear();
  }
  int function(unsigned long long a) { return (a * 97531) & mask; }
  T get(unsigned long long a) {
    int i = function(a);
    for (; key[i] != a && val[i] != 0;) i = (i + 1) & mask;
    if (key[i] != a) return 0;
    return val[i];
  }
  void set(unsigned long long a, T v) {
    int i = function(a);
    for (; key[i] != a && val[i] != 0;) i = (i + 1) & mask;
    key[i] = a;
    val[i] = v;
  }
  T increase(unsigned long long a, T v = 1) {
    int i = function(a);
    for (; key[i] != a && val[i] != 0;) i = (i + 1) & mask;
    key[i] = a;
    return val[i] += v;
  }
};
ullHash<int> _hash;
int dfs(int now, int l) {
  if (now > M) return 0;
  int i, j, k, hs = l + now * (M + 1);
  int res = 0, tmp;
  k = _hash.get(hs) - 1;
  if (k >= 0) return k;
  for (int i = -1; i <= 1; i++) {
    if (0 < l + i) {
      res = max(res, dfs(now + l + i, l + i));
    }
  }
  res += z[now];
  _hash.set(hs, res + 1);
  return res;
}
int main() {
  _hash.init(8000000, 8000000);
  int N;
  cin >> N >> D;
  for (int i = 0; i < N; i++) {
    int x;
    cin >> x;
    z[x]++;
  }
  for (int i = M - 1; i >= 0; i--) z1[i] = z[i] + z[i + 1];
  cout << dfs(D, D) << endl;
}
