#include <bits/stdc++.h>
using namespace std;
int d, dp[30001][500], cnt[30001];
void update(int i, int j, int l) {
  if (l <= 0 || i + l > 30000) return;
  int val = dp[i][j] + cnt[i + l];
  if (dp[i + l][l - d + 250] < val) dp[i + l][l - d + 250] = val;
}
int main() {
  int n;
  scanf("%d%d", &n, &d);
  for (int i = 1; i <= n; ++i) {
    int tmp;
    scanf("%d", &tmp);
    ++cnt[tmp];
  }
  memset(dp, -1, sizeof(dp));
  dp[d][250] = cnt[d];
  int ans = 0;
  for (int i = d; i <= 30000; ++i)
    for (int j = 0; j < 500; ++j)
      if (dp[i][j] != -1) {
        int l = d + j - 250;
        update(i, j, l - 1);
        update(i, j, l);
        update(i, j, l + 1);
        ans = max(ans, dp[i][j]);
      }
  printf("%d", ans);
  return 0;
}
