#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 30;
int dp[30006][2 * 260], arr[30006], d;
int solve(int n, int l) {
  int temp = abs(l - (d - 250));
  if (n > 30000) return 0;
  if (dp[n][temp] != -1) return dp[n][temp];
  if (l == 1)
    return dp[n][temp] = arr[n] + max(solve(n + l, l), solve(n + l + 1, l + 1));
  return dp[n][temp] =
             arr[n] + max(solve(n + l, l), max(solve(n + l - 1, l - 1),
                                               solve(n + l + 1, l + 1)));
}
int main() {
  int n, temp;
  memset((dp), (-1), sizeof(dp));
  scanf("%d %d", &n, &d);
  for (int i = 0; i < n; i++) {
    scanf("%d", &temp);
    arr[temp]++;
  }
  printf("%d\n", solve(d, d));
  return 0;
}
