#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void rread(T& num) {
  num = 0;
  T f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') num = num * 10 + ch - '0', ch = getchar();
  num *= f;
}
const int inf = 2e9, mod = 1e9 + 9;
const int maxn = 3e4 + 10;
const long double PI = acos(-1.0);
long long gcd(long long a, long long b) { return (a ? gcd(b % a, a) : b); }
void exgcd(long long a, long long b, long long& d, long long& x, long long& y) {
  if (!b) {
    d = a;
    x = 1;
    y = 0;
  } else {
    exgcd(b, a % b, d, y, x);
    y -= x * (a / b);
  }
}
long long power(long long a, long long n) {
  long long p = 1;
  while (n > 0) {
    if (n % 2) {
      p = p * a;
    }
    n >>= 1;
    a *= a;
  }
  return p;
}
long long power(long long a, long long n, long long mod) {
  long long p = 1;
  while (n > 0) {
    if (n % 2) {
      p = p * a;
      p %= mod;
    }
    n >>= 1;
    a *= a;
    a %= mod;
  }
  return p % mod;
}
int n, m;
int a[maxn];
int dp[maxn][650];
int be[maxn];
int main() {
  while (~scanf("%d%d", &n, &m)) {
    memset(a, 0, sizeof a);
    for (int i = 1; i <= n; i++) {
      int u;
      scanf("%d", &u);
      a[u]++;
    }
    int c = max(0, m - 299);
    for (int i = 0; i <= 30000; i++)
      for (int j = 0; j <= 647; j++) dp[i][j] = -1;
    dp[m][m - c] = a[m];
    int ans = a[m];
    for (int i = m + 1; i <= 30000; i++)
      for (int j = m - 299; j <= m + 299; j++)
        if (j >= 1 && j <= i) {
          if (i - j >= m && j >= 1)
            dp[i][j - c] = max(dp[i][j - c], dp[i - j][j - c]);
          if (i - j >= m && j - 1 >= 1 && j - 1 - c >= 0)
            dp[i][j - c] = max(dp[i][j - c], dp[i - j][j - 1 - c]);
          if (i - j >= m && j + 1 >= 2)
            dp[i][j - c] = max(dp[i][j - c], dp[i - j][j + 1 - c]);
          if (dp[i][j - c] != -1)
            dp[i][j - c] += a[i], ans = max(ans, dp[i][j - c]), be[i] = i - j;
        }
    cout << ans << endl;
  }
  return 0;
}
