#include <bits/stdc++.h>
using namespace std;
int dcmp(double a, double b) {
  return fabs(a - b) <= 1e-10 ? 0 : a < b ? -1 : 1;
}
const int MAX = 30001;
int dp[MAX][500];
int n, d, arr[MAX], tmp;
int sol(int i, int j) {
  if (i >= MAX) return 0;
  int n_j = j - (d - 250);
  int &ret = dp[i][n_j];
  if (ret != -1) return ret;
  if (j == 1) {
    ret = arr[i] + max(sol(i + j, j), sol(i + j + 1, j + 1));
  } else {
    ret = arr[i] +
          max({sol(i + j, j), sol(i + j + 1, j + 1), sol(i + j - 1, j - 1)});
  }
  return ret;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  memset(dp, -1, sizeof(dp));
  cin >> n >> d;
  for (int i = 0; i < (int)(n); ++i) {
    cin >> tmp;
    arr[tmp]++;
  }
  cout << sol(d, d) << '\n';
}
