#include <bits/stdc++.h>
using namespace std;
int n, m, i, j, k, l, a[1000009], b[1000009], dp[30005][250][5], ans, cn, t, x,
    y, z, mx, mn, s, d;
int go(int pos, int var, int flag) {
  if (pos > 30000) {
    return 0;
  }
  if (dp[pos][var][flag] != -1) {
    return dp[pos][var][flag];
  } else {
    int ret = 0, jump;
    if (flag == 1) {
      jump = d - var;
      var = -var;
    } else {
      jump = d + var;
    }
    if (jump > 1) {
      if (var - 1 < 0) {
        ret = max(ret, a[pos] + go(pos + jump - 1, abs(var - 1), 1));
      } else {
        ret = max(ret, a[pos] + go(pos + jump - 1, abs(var - 1), 0));
      }
    }
    ret = max(ret, a[pos] + go(pos + jump, abs(var), flag));
    if (var + 1 < 0) {
      ret = max(ret, a[pos] + go(pos + jump + 1, abs(var + 1), 1));
    } else {
      ret = max(ret, a[pos] + go(pos + jump + 1, abs(var + 1), 0));
    }
    return dp[pos][abs(var)][flag] = ret;
  }
}
int main() {
  while (scanf("%d %d", &n, &d) != EOF) {
    memset(dp, -1, sizeof(dp));
    memset(a, 0, sizeof(a));
    for (i = 0; i < n; i++) {
      scanf("%d", &x);
      a[x]++;
    }
    ans = go(d, 0, 0);
    printf("%d\n", ans);
  }
  return 0;
}
