#include <bits/stdc++.h>
static const int N = 600;
static const int M = 30010;
static const int LEN = 50;
static const int MAX = 0x7fffffff;
static const int GMAX = 0x3f3f3f3f;
static const long long LGMAX = 0x3f3f3f3f3f3f3f3f;
static const int MIN = ~MAX;
static const double EPS = 1e-9;
static const int BASE = 1000000007;
static const int CH = 258;
int hash[M];
int dp[M][N];
bool used[M][N];
int solve(int i, int j, int d, int len) {
  if (i > len) return 0;
  int jj = j - d + 250;
  if (used[i][jj]) return dp[i][jj];
  used[i][jj] = true;
  int res = 0;
  if (j == 1) {
    dp[i][jj] = hash[i] + std::max(solve(i + j, j, d, len),
                                   solve(i + j + 1, j + 1, d, len));
  } else {
    dp[i][jj] = hash[i] + std::max(std::max(solve(i + j, j, d, len),
                                            solve(i + j + 1, j + 1, d, len)),
                                   solve(i + j - 1, j - 1, d, len));
  }
  return dp[i][jj];
}
int main() {
  0;
  0;
  int n, d;
  while (scanf("%d %d", &n, &d) != EOF) {
    int tmp;
    int len = -1;
    for (int i = 0; i < n; ++i) {
      scanf("%d", &tmp);
      ++hash[tmp];
      len = std::max(len, tmp);
    }
    printf("%d\n", solve(d, d, d, len));
    memset(hash, 0, sizeof(hash));
    memset(dp, 0, sizeof(dp));
    memset(used, -1, sizeof(used));
  }
  return 0;
}
