#include <bits/stdc++.h>
using namespace std;
void print_vector(vector<int> v);
void print_array(int* array, int start, int end);
int islands[30010], x, n, dd;
int memo[30010][400];
int solve(int pos, int d) {
  if (d == 0) return 0;
  if (pos > 30000) return 0;
  if (memo[pos][d - dd + 200] != -1) return memo[pos][d - dd + 200];
  return memo[pos][d - dd + 200] =
             islands[pos] +
             max(solve(pos + d, d),
                 max(solve(pos + d - 1, d - 1), solve(pos + d + 1, d + 1)));
}
int main() {
  scanf("%d", &n), scanf("%d", &dd);
  memset(islands, 0, sizeof islands);
  for (int i = (0), _b = (n); i < _b; i++) {
    scanf("%d", &x);
    islands[x]++;
  }
  memset(memo, -1, sizeof memo);
  printf("%d\n", solve(dd, dd));
  return 0;
}
void print_array(int* array, int start, int end) {
  printf("[");
  for (int i = (start), _b = (end); i < _b; i++) {
    printf("%d ", array[i]);
  }
  printf("]");
  printf("\n");
}
void print_vector(vector<int> v) {
  printf("[");
  for (int i = (0), _b = (v.size()); i < _b; i++) {
    printf("%d ", v[i]);
  }
  printf("]");
  printf("\n");
}
