#include <bits/stdc++.h>
using namespace std;
int n, d, maxa;
map<int, int> gems;
int jyh[31000][600];
int max3(int a, int b, int c) { return max(a, max(b, c)); }
int dfs(int now, int sd) {
  if (sd <= 0 || now > maxa) return 0;
  if (jyh[now][sd] != -1) return jyh[now][sd];
  int then = max3(dfs(now + sd, sd), dfs(now + (sd - 1), sd - 1),
                  dfs(now + (sd + 1), sd + 1));
  jyh[now][sd] = gems[now] + then;
  return then + gems[now];
}
int main() {
  memset(jyh, -1, sizeof(jyh));
  cin >> n >> d;
  for (int i = 1; i <= n; i++) {
    int a;
    scanf("%d", &a);
    gems[a]++;
    maxa = max(maxa, a);
  }
  cout << dfs(d, d) + gems[0];
  return 0;
}
