#include <bits/stdc++.h>
using namespace std;
const int MN = 3 * 100 * 100 * 2, lim = 30001;
int n, d, gem[MN], dp[MN][400];
bool mark[MN][400];
long long f(int cur, int j) {
  if (mark[cur][j - d + 200]) return dp[cur][j - d + 200];
  if (j <= 0 || cur > lim) return 0;
  if (cur + j > lim) return gem[cur];
  long long ret = gem[cur];
  ret += max(f(cur + j, j + 1), max(f(cur + j, j - 1), f(cur + j, j)));
  mark[cur][j - d + 200] = true;
  dp[cur][j - d + 200] = ret;
  return ret;
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> d;
  for (int i = 0; i < n; i++) {
    int p;
    cin >> p;
    gem[p]++;
  }
  cout << max(f(d, d + 1), max(f(d, d - 1), f(d, d)));
  return 0;
}
