#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e4 + 600;
const int N = 3e4;
const int inf = 1000000;
int n, d;
int p[maxn], num[maxn], dp[maxn][505];
int main() {
  scanf("%d%d", &n, &d);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &p[i]);
    num[p[i]]++;
  }
  memset(dp, -inf, sizeof(dp));
  dp[d][250] = num[d];
  for (int i = 1; i <= N; i++) {
    for (int j = 0; j <= 500; j++) {
      int x = j - 250 + d;
      if (i + x > i && i + x <= N)
        dp[i + x][j] = max(dp[i + x][j], dp[i][j] + num[i + x]);
      if (i + x + 1 > i && i + x + 1 <= N)
        dp[i + x + 1][j + 1] =
            max(dp[i + x + 1][j + 1], dp[i][j] + num[i + x + 1]);
      if (i + x - 1 > i && i + x - 1 <= N)
        dp[i + x - 1][j - 1] =
            max(dp[i + x - 1][j - 1], dp[i][j] + num[i + x - 1]);
    }
  }
  int ans = 0;
  for (int i = 1; i <= N; i++) {
    for (int j = 0; j <= 500; j++) {
      ans = max(ans, dp[i][j]);
    }
  }
  cout << ans << "\n";
}
