#include <bits/stdc++.h>
using namespace std;
int dp[30007][507], trea[30007];
int main() {
  int n, k;
  while (scanf("%d%d", &n, &k) != EOF) {
    int a;
    memset(dp, -1, sizeof(dp));
    memset(trea, 0, sizeof(trea));
    for (int i = 0; i < n; i++) {
      scanf("%d", &a);
      trea[a]++;
    }
    dp[k][250] = trea[k];
    int ans = dp[k][250];
    for (int i = k; i <= 30000; i++)
      for (int j = 1; j <= 500; j++) {
        if (dp[i][j] == -1) continue;
        int to = i + k + j - 250;
        if (to <= 30000) {
          dp[to][j] = max(dp[to][j], dp[i][j] + trea[to]);
          ans = max(ans, dp[to][j]);
        }
        if (to + 1 <= 30000) {
          dp[to + 1][j + 1] = max(dp[to + 1][j + 1], dp[i][j] + trea[to + 1]);
          ans = max(ans, dp[to + 1][j + 1]);
        }
        if (to - i > 1 && to <= 30000) {
          dp[to - 1][j - 1] = max(dp[to - 1][j - 1], dp[i][j] + trea[to - 1]);
          ans = max(ans, dp[to - 1][j - 1]);
        }
      }
    printf("%d\n", ans);
  }
  return 0;
}
