#include <bits/stdc++.h>
using namespace std;
int dp[30001][2000], a[40000], n, d, x, ma = -1;
int dfs(int x, int diff) {
  if (x > ma) return 0;
  if (x > 30000) return 0;
  if (diff <= 0) return 0;
  if (dp[x][diff] != -1) return dp[x][diff];
  int &ret = dp[x][diff], ret1 = 0, ret2 = 0, ret3 = 0;
  ret = 0;
  if (a[x]) ret += a[x];
  ret1 = dfs(x + diff - 1, diff - 1);
  ret2 = dfs(x + diff, diff);
  ret3 = dfs(x + diff + 1, diff + 1);
  ret += max(max(ret1, ret2), ret3);
  return ret;
}
int dfs1(int curr, int diff) {
  if (curr > ma) return 0;
  if (curr > 30000) return 0;
  if (diff <= 0) return 0;
  int ret = a[curr];
  int ret1 = dfs1(curr + diff - 1, diff - 1);
  int ret2 = dfs1(curr + diff, diff);
  int ret3 = dfs1(curr + diff + 1, diff + 1);
  ret += max(max(ret1, ret2), ret3);
  return ret;
}
int main() {
  cin >> n >> d;
  for (int i = 0; i < n; i++) cin >> x, a[x]++, ma = max(ma, x);
  if (d < 2000) {
    memset(dp, -1, sizeof dp);
    cout << dfs(d, d) << endl;
  } else {
    cout << dfs1(d, d) << endl;
  }
  return 0;
}
