#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int N = 30000 + 9;
int a[N];
long long dp[N][509], n, d;
long long go(int ind, int jmp) {
  if (ind > 30000) return 0;
  long long &ret = dp[ind][jmp - d + 250];
  if (ret != -1) return ret;
  ret = go(ind + jmp, jmp) + a[ind];
  ret = max(ret, a[ind] + go(ind + jmp + 1, jmp + 1));
  if (jmp > 1) {
    ret = max(ret, a[ind] + go(ind + jmp - 1, jmp - 1));
  }
  return ret;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> d;
  for (int i = 1; i <= n; i++) {
    int foo;
    cin >> foo;
    a[foo]++;
  }
  memset(dp, -1, sizeof dp);
  cout << go(d, d);
  return 0;
}
