#include <bits/stdc++.h>
using namespace std;
int mem[30010][600];
int dp[30010][600];
int in[30010], d, Lim;
int solve(int curr, int prev) {
  int& res = mem[curr][prev];
  if (mem[curr][prev] != -1) return res;
  int l = abs(curr - prev);
  int a = l - 1, b = l, c = l + 1, i = 0, j = 0, k = 0;
  if (curr + a <= Lim && a > 0) i = solve(curr + a, curr);
  if (curr + b <= Lim && b > 0) j = solve(curr + b, curr);
  if (curr + c <= Lim && c > 0) k = solve(curr + c, curr);
  res = in[curr] + max(max(i, j), k);
  return res;
}
int solve2(int curr, int l) {
  int& res = mem[curr][l];
  if (mem[curr][l] != -1) return res;
  int a = l - 1, b = l, c = l + 1, i = 0, j = 0, k = 0;
  if (curr + a <= Lim && a > 0) i = solve2(curr + a, a);
  if (curr + b <= Lim && b > 0) j = solve2(curr + b, b);
  if (curr + c <= Lim && c > 0) k = solve2(curr + c, c);
  res = in[curr] + max(max(i, j), k);
  return res;
}
int solve4(int curr, int shift) {
  int& res = mem[curr][shift + 250];
  if (mem[curr][shift + 250] != -1) return res;
  int l = d + shift;
  int a = l - 1, b = l, c = l + 1, i = 0, j = 0, k = 0;
  if (curr + a <= Lim && a > 0) i = solve4(curr + a, shift - 1);
  if (curr + b <= Lim && b > 0) j = solve4(curr + b, shift);
  if (curr + c <= Lim && c > 0) k = solve4(curr + c, shift + 1);
  res = in[curr] + max(max(i, j), k);
  return res;
}
int solve3(int curr, int l) {
  int offset = l - d + 260;
  int& res = mem[curr][offset];
  if (mem[curr][offset] != -1) return res;
  int a = l - 1, b = l, c = l + 1, i = 0, j = 0, k = 0;
  if (curr + a <= Lim && a > 0) i = solve3(curr + a, a);
  if (curr + b <= Lim && b > 0) j = solve3(curr + b, b);
  if (curr + c <= Lim && c > 0) k = solve3(curr + c, c);
  res = in[curr] + max(max(i, j), k);
  return res;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int t, n, var, ans = 0;
  cin >> n >> d;
  Lim = 0;
  for (int i = 0; i < n; i++) {
    cin >> var;
    Lim = max(Lim, var);
    in[var] += 1;
  }
  memset(mem, -1, sizeof mem);
  ans = solve3(d, d);
  cout << ans << '\n';
  return 0;
}
