#include <bits/stdc++.h>
using namespace std;
int dp[610][30010];
int gem[30010];
int N, D;
int mxn = 30000;
int main() {
  int i, p, len;
  scanf("%d%d", &N, &D);
  for (i = 0; i < N; ++i) {
    scanf("%d", &p);
    gem[p]++;
  }
  for (i = mxn; i >= D; --i) {
    for (p = 0; p <= 600; ++p) {
      len = D - p + 300;
      if (len > i || len <= 0) continue;
      dp[p][i] = gem[i];
      if (i + len <= mxn) dp[p][i] = max(dp[p][i], dp[p][i + len] + gem[i]);
      if (p && i + len + 1 <= mxn)
        dp[p][i] = max(dp[p][i], dp[p - 1][i + len + 1] + gem[i]);
      if (len > 1 && i + len - 1 <= mxn)
        dp[p][i] = max(dp[p][i], dp[p + 1][i + len - 1] + gem[i]);
    }
  }
  printf("%d\n", dp[300][D]);
  return 0;
}
