#include <bits/stdc++.h>
using namespace std;
int dp[31000][607];
int cnt[32000];
int d;
int encode[60610];
int decode[60610];
int main() {
  ios_base::sync_with_stdio(0);
  cout.precision(9);
  cout << fixed;
  int n;
  cin >> n >> d;
  int c = 1;
  for (int i = max(1, d - 300); i <= d + 300; ++i, ++c) {
    encode[i] = c;
    decode[c] = i;
  }
  for (int i = 0; i < 31000; ++i)
    for (int j = 0; j < 607; ++j) dp[i][j] = -100000000;
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    cnt[x]++;
  }
  dp[d][encode[d]] = cnt[d];
  for (int i = d + 1; i < 31000; ++i) {
    for (int j = 1; j <= 600; ++j) {
      int jump = decode[j];
      if (jump > i || jump <= 0) continue;
      int val = dp[i][j];
      if (encode[jump + 1] <= 600 && encode[jump + 1] > 0) {
        val = max(val, dp[i - jump][encode[jump + 1]] + cnt[i]);
      }
      if (encode[jump - 1] <= 600 && encode[jump - 1] > 0) {
        val = max(val, dp[i - jump][encode[jump - 1]] + cnt[i]);
      }
      val = max(val, dp[i - jump][encode[jump]] + cnt[i]);
      dp[i][j] = val;
    }
  }
  int mx = 0;
  for (int i = 0; i < 31000; ++i)
    for (int j = 0; j < 607; ++j) mx = max(mx, dp[i][j]);
  cout << mx << "\n";
  return 0;
}
