#include <bits/stdc++.h>
using namespace std;
int dp[30005][505];
int a[30005];
int main() {
  int n, d;
  scanf("%d%d", &n, &d);
  for (int i = 0; i < n; i++) {
    int x;
    scanf("%d", &x);
    a[x]++;
  }
  memset(dp, (-1), sizeof(dp));
  dp[d][250] = 0;
  int ans = 0;
  for (int i = d; i <= 30001; i++) {
    for (int j = 0; j <= 500; j++) {
      if (dp[i][j] == -1) continue;
      dp[i][j] += a[i];
      ans = max(ans, dp[i][j]);
      for (int k = j - 1; k <= j + 1; k++) {
        int ne = i + k - 250 + d;
        if (ne <= i || k <= 0 || ne > 30001) continue;
        dp[ne][k] = max(dp[ne][k], dp[i][j]);
      }
    }
  }
  printf("%d\n", ans);
  return 0;
}
