#include <bits/stdc++.h>
using namespace std;
int dp[30002][247 * 2];
bool use[30002][247 * 2];
int countt[30002];
int base[30002];
int n, d;
inline int dfs(int a, int b) {
  if (a > 30000) {
    return 0;
  }
  int ich = b - base[a];
  if (use[a][ich]) {
    return dp[a][ich];
  }
  use[a][ich] = true;
  dp[a][ich] = dfs(a + b, b);
  dp[a][ich] = max(dp[a][ich], dfs(a + b + 1, b + 1));
  if (b > 1) {
    dp[a][ich] = max(dp[a][ich], dfs(a + b - 1, b - 1));
  }
  dp[a][ich] += countt[a];
  return dp[a][ich];
}
int main() {
  scanf("%d%d", &n, &d);
  for (int i = 0; i < n; i++) {
    int a;
    scanf("%d", &a);
    countt[a]++;
  }
  base[d] = d;
  for (int i = d; i + 1 < 30000; i++) {
    base[i + 1] = max(0, base[i] - 1);
  }
  int ans = dfs(d, d);
  printf("%d\n", ans);
  return 0;
}
