#include <bits/stdc++.h>
using namespace std;
int gem[30010];
int dp[30010][505];
int pivot;
int dfs(int pos, int l) {
  int &ret = dp[pos][l - pivot], add = 0;
  if (ret != -1) return ret;
  if (pos + l + 1 <= 30000) add = dfs(pos + l + 1, l + 1);
  if (pos + l <= 30000) add = max(add, dfs(pos + l, l));
  if (pos + l - 1 <= 30000 && l - 1 > 0)
    add = max(add, dfs(pos + l - 1, l - 1));
  return ret = gem[pos] + add;
}
int main() {
  memset(dp, -1, sizeof dp);
  int m, d;
  scanf("%d%d", &m, &d);
  while (m--) {
    int pos;
    scanf("%d", &pos);
    ++gem[pos];
  }
  pivot = d - 252;
  printf("%d\n", dfs(d, d));
  return 0;
}
