#include <bits/stdc++.h>
using namespace std;
int a[30010];
int dp[550][30010];
void inline upd(int &x, int t) {
  if (x < t) x = t;
}
int main() {
  int n, d, x;
  scanf("%d%d", &n, &d);
  for (int i = 0; i < n; i++) {
    scanf("%d", &x);
    a[x]++;
  }
  int lo = d;
  x = d;
  while (x <= 30000) {
    if (lo <= 1) break;
    --lo;
    x += lo;
  }
  int hi = d;
  x = d;
  while (x <= 30000) {
    ++hi;
    x += hi;
  }
  int ans = 0;
  for (int i = d; i <= 30000; i++) {
    for (int j = 0; j < 550; j++) {
      dp[j][i] = -1;
    }
  }
  dp[d - lo][d] = a[d];
  for (int i = d; i <= 30000; i++) {
    for (int j = lo; j <= hi; j++) {
      if (dp[j - lo][i] == -1) continue;
      upd(ans, dp[j - lo][i]);
      for (int k = max(j - 1, lo); k <= j + 1; k++) {
        if (i + k <= 30000) {
          upd(dp[k - lo][i + k], dp[j - lo][i] + a[i + k]);
        }
      }
    }
  }
  printf("%d\n", ans);
  return 0;
}
