#include <bits/stdc++.h>
using namespace std;
int k;
vector<vector<int>> dp(30001 + 1, vector<int>(506, -1));
vector<int> arr(30001 + 1);
int solve(int index, int jump) {
  if (index > 30001) return 0;
  int tradution = jump - (k - 246);
  if (dp[index][tradution] != -1) return dp[index][tradution];
  if (jump == 1)
    return dp[index][tradution] =
               arr[index] + max(solve(index + jump, jump),
                                solve(index + jump + 1, jump + 1));
  return dp[index][tradution] =
             arr[index] + max(solve(index + jump - 1, jump - 1),
                              max(solve(index + jump, jump),
                                  solve(index + jump + 1, jump + 1)));
}
int main() {
  int n, i, num;
  scanf("%d%d", &n, &k);
  for (i = 0; i < n; i++) {
    scanf("%d", &num);
    arr[num]++;
  }
  printf("%d\n", solve(k, k));
  return 0;
}
