#include <bits/stdc++.h>
using namespace std;
const int maxn = 33333;
const int fuck = 30000;
int n, d;
struct node {
  int d, v;
};
vector<node> g[maxn];
int val[maxn];
bool vis[maxn];
bool cmp1(const node &a, const node &b) { return a.v > b.v; }
int ans;
int main() {
  scanf("%d %d", &n, &d);
  int maxx = 0;
  for (int i = 0; i < n; i++) {
    int cmp;
    scanf("%d", &cmp);
    maxx = max(maxx, cmp);
    val[cmp]++;
  }
  g[d].push_back((node){d, val[d]});
  int dd, vv;
  for (int i = d; i <= maxx; i++) {
    memset(vis, 0, sizeof(vis));
    sort(g[i].begin(), g[i].end(), cmp1);
    for (int j = 0; j < g[i].size(); j++) {
      dd = g[i][j].d;
      vv = g[i][j].v;
      if (vis[dd]) continue;
      vis[dd] = 1;
      ans = max(ans, vv);
      if (dd > 1)
        if (i + dd - 1 <= maxx)
          g[i + dd - 1].push_back((node){dd - 1, vv + val[i + dd - 1]});
      if (dd < maxx)
        if (i + dd + 1 <= maxx)
          g[i + dd + 1].push_back((node){dd + 1, vv + val[i + dd + 1]});
      if (i + dd <= maxx) g[i + dd].push_back((node){dd, vv + val[i + dd]});
    }
  }
  printf("%d\n", ans);
  return 0;
}
