#include <bits/stdc++.h>
using namespace std;
long long mul(long long a, long long b) { return (a * b) % (100000007); }
long long add(long long a, long long b) { return (a + b) % (100000007); }
long long sub(long long a, long long b) {
  return (a - b + (a - b) / (100000007) * (100000007) + (100000007)) %
         (100000007);
}
int n, d, a[(30000 + 10)] = {0}, s[(30000 + 10)] = {0},
                     f[(30000 + 10)][(250 + 10) * 2] = {0};
int main() {
  cin >> n >> d;
  for (int i = 1; i <= n; i++) {
    int p;
    scanf("%d", &p);
    a[p]++;
  }
  for (int i = 1; i <= (30001); i++) s[i] = s[i - 1] + a[i];
  int ans = 0;
  memset(f, -1, sizeof(f));
  ans = f[d][(250)] = a[d];
  for (int i = d; i <= (30001); i++) {
    for (int j = 0; j < 2 * (250) + 1; j++)
      if (f[i][j] >= 0) {
        int dis = j - (250) + d;
        if (dis > 0 && i + dis <= (30001)) {
          f[i + dis][j] = max(f[i + dis][j], f[i][j] + a[i + dis]);
          ans = max(ans, f[i + dis][j]);
        }
        if (i + dis + 1 <= (30001)) {
          f[i + dis + 1][j + 1] =
              max(f[i + dis + 1][j + 1], f[i][j] + a[i + dis + 1]);
          ans = max(ans, f[i + dis + 1][j + 1]);
        }
        if (dis - 1 > 0 && i + dis - 1 <= (30001)) {
          f[i + dis - 1][j - 1] =
              max(f[i + dis - 1][j - 1], f[i][j] + a[i + dis - 1]);
          ans = max(ans, f[i + dis - 1][j - 1]);
        }
      }
  }
  cout << ans << endl;
  return 0;
}
