#include <bits/stdc++.h>
using namespace std;
int d;
int cnt[30005];
int dp[30005][605];
int solve(int pos, int l) {
  if (pos > 30000) return 0;
  if (dp[pos][300 + l] != -1) return dp[pos][300 + l];
  int ret = 0;
  int jump = d + l;
  if (jump - 1 > 0) ret = max(ret, solve(pos + jump - 1, l - 1));
  ret = max(ret, solve(pos + jump, l));
  ret = max(ret, solve(pos + jump + 1, l + 1));
  ret += cnt[pos];
  return dp[pos][300 + l] = ret;
}
int main() {
  int n;
  scanf("%d %d", &n, &d);
  for (int i = 1; i <= n; i++) {
    int x;
    scanf("%d", &x);
    cnt[x]++;
  }
  memset(dp, -1, sizeof(dp));
  int ans = solve(d, 0);
  printf("%d\n", ans);
  return 0;
}
