#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 7;
const long double eps = 1e-16;
const int maxn = 110000;
int a[31000];
vector<pair<int, int> > f[31000];
int main() {
  int n, d;
  scanf("%d%d", &n, &d);
  for (int i = 0; i < n; i++) {
    int x;
    scanf("%d", &x);
    a[x]++;
  }
  f[0].push_back(pair<int, int>(d, a[0]));
  int ans = 0;
  for (int i = 0; i <= 30000; i++) {
    sort(f[i].rbegin(), f[i].rend());
    for (int j = 0; j < f[i].size(); j++) {
      if (j && f[i][j].first == f[i][j - 1].first) continue;
      ans = max(ans, f[i][j].second);
      for (int k = max(1, f[i][j].first - (i > 0));
           k <= min(30000 - i, f[i][j].first + (i > 0)); k++) {
        f[i + k].push_back(pair<int, int>(k, f[i][j].second + a[i + k]));
      }
    }
  }
  printf("%d", ans);
  return 0;
}
