#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 30100;
int num[MAX_N], d;
int dp[MAX_N][550];
int dfs(int x, int ch) {
  int res = 0;
  if (x > 30000) return 0;
  if (dp[x][ch + 250] != -1) return dp[x][ch + 250];
  if (d + ch == 1) {
    dp[x][ch + 250] = num[x] + dfs(x + 1, ch);
    return dp[x][ch + 250];
  }
  res = max(res, num[x] + dfs(x + d + ch - 1, ch - 1));
  res = max(res, num[x] + dfs(x + d + ch, ch));
  res = max(res, num[x] + dfs(x + d + ch + 1, ch + 1));
  dp[x][ch + 250] = res;
  return res;
}
int main(void) {
  int n, i, x;
  scanf("%d%d", &n, &d);
  for (i = 1; i <= n; i++) {
    scanf("%d", &x);
    num[x]++;
  }
  memset(dp, -1, sizeof(dp));
  printf("%d\n", dfs(d, 0));
  return 0;
}
