#include <bits/stdc++.h>
using namespace std;
int n, d;
int dist[30005];
int lz;
map<pair<int, int>, int> dp;
bool cek[30005][1000];
int depe[30005][1000];
int selisih;
int cnt(int pulau, int loncat) {
  int index = loncat - selisih;
  if (pulau >= 30001) return 0;
  if (cek[pulau][index]) return depe[pulau][index];
  cek[pulau][index] = true;
  if (loncat == 1) {
    int max1 = cnt(pulau + loncat, loncat);
    int max2 = cnt(pulau + loncat + 1, loncat + 1);
    depe[pulau][index] = dist[pulau] + max(max1, max2);
  } else {
    int max1 = cnt(pulau + loncat, loncat);
    int max2 = cnt(pulau + loncat + 1, loncat + 1);
    int max3 = cnt(pulau + loncat - 1, loncat - 1);
    depe[pulau][index] = dist[pulau] + max(max(max1, max2), max3);
  }
  return depe[pulau][index];
}
int main() {
  scanf("%d %d", &n, &d);
  memset(depe, -1, sizeof(dp));
  memset(cek, false, sizeof(cek));
  memset(dist, 0, sizeof(dist));
  selisih = d - 250;
  for (int i = 0; i < n; i++) {
    int temp;
    scanf("%d", &temp);
    dist[temp] += 1;
  }
  printf("%d", cnt(d, d));
  return 0;
}
