#include <bits/stdc++.h>
using namespace std;
int n, d;
int p[30010];
int table[30010];
int dp[30010][210];
int dfs(int cur, int len, int inx) {
  if (cur > 30000) return 0;
  if (dp[cur][inx] > -1) {
    return dp[cur][inx];
  }
  int tot = p[cur];
  int maxVal = 0;
  for (int i = -1; i <= 1; ++i) {
    if (len + i <= 0) continue;
    maxVal = max(maxVal, dfs(cur + len + i, len + i, table[len + i]));
  }
  return dp[cur][inx] = tot + maxVal;
}
int main() {
  int a;
  while (cin >> n >> d) {
    memset(p, 0, sizeof(p));
    for (int i = 1; i <= n; ++i) {
      scanf("%d", &a);
      p[a]++;
    }
    memset(table, 0, sizeof(table));
    int cnt = 0;
    table[d] = cnt;
    cnt++;
    for (int i = 1; i <= 30000; ++i) {
      if (i == d) continue;
      if (abs(i - d) <= 175) {
        table[i] = cnt;
        cnt++;
      }
    }
    memset(dp, -1, sizeof(dp));
    int ans = dfs(d, d, 0);
    printf("%d\n", ans);
  }
  return 0;
}
