#include <bits/stdc++.h>
int begin = -1;
int max = 10000;
std::map<int, int> gems;
int dp[30001][501];
long long calc(int current, int l) {
  if (current > max) return 0;
  if (dp[current][l - begin] != -1) return dp[current][l - begin];
  long long found = 0;
  if (gems.find(current) != gems.end()) found += gems[current];
  long long found2 = 0;
  for (int i = l - 1; i <= l + 1; i++) {
    if (i == 0) continue;
    long long temp;
    temp = calc(current + i, i);
    if (temp > found2) found2 = temp;
  }
  return dp[current][l - begin] = (found + found2);
}
int main() {
  int n, d;
  scanf("%d", &n);
  scanf("%d", &d);
  for (int i = 1; i <= n; i++) {
    int x;
    scanf("%d", &x);
    if (gems.find(x) != gems.end()) {
      int v = gems[x];
      gems[x] = ++v;
    } else {
      gems[x] = 1;
    }
    if (i == n) max = x;
  }
  for (int i = 0; i < 30001; i++) {
    for (int j = 0; j < 501; j++) {
      dp[i][j] = -1;
    }
  }
  begin = d - 250;
  printf("%d\n", calc(d, d));
  return 0;
}
