#include <bits/stdc++.h>
using namespace std;
int dp[30003][500];
int n, d, last;
int cnt[30003], v;
int test(int p, int l) {
  if (p > last) return 0;
  int &ret = dp[p][l + 250];
  if (ret != -1) return ret;
  ret = 0;
  ret = max(ret, test(p + d + l, l));
  if (d + l > 1) ret = max(ret, test(p + d + l - 1, l - 1));
  ret = max(ret, test(p + d + l + 1, l + 1));
  return ret += cnt[p];
}
int main() {
  scanf("%d %d", &n, &d);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &v);
    cnt[v]++;
    last = max(last, v);
  }
  memset(dp, -1, sizeof dp);
  printf("%d\n", test(d, 0));
  return 0;
}
