#include <bits/stdc++.h>
using namespace std;
int dp[30001][600];
int gem[30001];
int last;
int d;
int solve(int loc, int prevStep) {
  if (loc > last || loc < 0) return 0;
  if (dp[loc][(prevStep - d) + 300] != -1) return dp[loc][(prevStep - d) + 300];
  int ch1 = (gem[loc]);
  int ch2 = (gem[loc]);
  int ch3 = (gem[loc]);
  if (prevStep + 1 > 0)
    ch1 = max(ch1, ch1 + solve(loc + prevStep + 1, prevStep + 1));
  if (prevStep - 1 > 0)
    ch2 = max(ch2, ch2 + solve(loc + prevStep - 1, prevStep - 1));
  if (prevStep > 0) ch3 = max(ch3, ch3 + solve(loc + prevStep, prevStep));
  return dp[loc][(prevStep - d) + 300] = max(ch1, max(ch3, ch2));
}
int main() {
  last = 0;
  for (int i = 0; i <= 30000; i++) gem[i] = 0;
  memset(dp, -1, sizeof dp);
  int n, a;
  cin >> n >> d;
  for (int i = 0; i < n; i++) {
    scanf("%d", &a);
    last = max(last, a);
    gem[a]++;
  }
  cout << solve(d, d);
}
