#include <bits/stdc++.h>
using namespace std;
const int MAX = 30001;
int dp[MAX][501], n, d, a[MAX];
bool used[MAX][501];
int calc(int i, int j) {
  int jj = j - (d - 250);
  int &ret = dp[i][jj];
  if (i >= MAX) return 0;
  if (used[i][jj]) return dp[i][jj];
  used[i][jj] = true;
  ret = 0;
  int ans = 0;
  if (j == 1) {
    ans = a[i] + max(calc(i + j, j), calc(i + j + 1, j + 1));
  } else if (j >= 2) {
    ans = a[i] + max(max(calc(i + j - 1, j - 1), calc(i + j, j)),
                     calc(i + j + 1, j + 1));
  }
  ret = ans;
  return ans;
}
int main() {
  cin >> n >> d;
  for (int i = 0; i < n; i++) {
    int tmp;
    cin >> tmp;
    a[tmp]++;
  }
  cout << calc(d, d);
  return 0;
}
