#include <bits/stdc++.h>
using namespace std;
const int N = 3e4 + 100;
int dp[N][500];
int m[N];
int n, d, ans;
int range;
int solve(int a, int b) {
  if (a > range) return 0;
  int &ret = dp[a][b];
  if (ret != -1) return ret;
  if (b > 1) {
    ret = max(ret, solve(a + b - 1, b - 1) + m[a]);
  }
  ret = max(ret, solve(a + b + 1, b + 1) + m[a]);
  ret = max(ret, solve(a + b, b) + m[a]);
  ans = max(ans, ret);
  return ret;
}
int main() {
  scanf("%d%d", &n, &d);
  for (int i = 0; i < n; ++i) {
    int x;
    scanf("%d", &x);
    m[x]++;
    range = max(range, x);
  }
  memset(dp, -1, sizeof(dp));
  solve(d, d);
  cout << ans << "\n";
  return 0;
}
