#include <bits/stdc++.h>
#pragma warning(disable : 4996)
using namespace std;
map<int, int> dp[33333];
map<int, int>::iterator it;
int f[33333][500] = {0};
int cnt[33333] = {0};
int n, m;
int ans = 0;
int main() {
  cin >> n >> m;
  int x;
  for (int i = 1; i <= n; i++) cin >> x, cnt[x]++;
  memset(f, -1, sizeof(f));
  f[m][250] = cnt[m];
  for (int i = m; i <= 30000; i++)
    for (int j = 1; j <= 500; j++)
      if (f[i][j] != -1) {
        int k = f[i][j];
        ans = max(k, ans);
        if (i + m + j - 251 > 30000) continue;
        f[i + m + j - 250][j] =
            max(k + cnt[i + m + j - 250], f[i + m + j - 250][j]);
        f[i + m + j - 249][j + 1] =
            max(k + cnt[i + m + j - 249], f[i + m + j - 249][j + 1]);
        if (m + j - 251)
          f[i + m + j - 251][j - 1] =
              max(k + cnt[i + m + j - 251], f[i + m + j - 251][j - 1]);
      }
  cout << ans << endl;
  return 0;
}
