#include <bits/stdc++.h>
using namespace std;
int n, d, mx, ans;
int dp[30001][603], gems[30001], f[30001][603];
int main() {
  cin >> n >> d;
  for (int i = 1; i <= n; i++) {
    int x;
    cin >> x;
    gems[x]++;
    mx = max(x, mx);
  }
  f[d][300] = 1;
  dp[d][300] = gems[d];
  for (int i = 2 * d - 1; i <= mx; i++) {
    for (int j = 1; j <= 601; j++) {
      int dist = d - (300 - j);
      if (dist >= i) continue;
      if (dist <= 0) continue;
      if (f[i - dist][j] == 1) {
        dp[i][j] = max(dp[i][j], dp[i - dist][j] + gems[i]);
        f[i][j] = 1;
      }
      if (f[i - dist][j + 1] == 1) {
        dp[i][j] = max(dp[i][j], dp[i - dist][j + 1] + gems[i]);
        f[i][j] = 1;
      }
      if (f[i - dist][j - 1] == 1) {
        dp[i][j] = max(dp[i][j], dp[i - dist][j - 1] + gems[i]);
        f[i][j] = 1;
      }
    }
  }
  for (int i = d; i <= mx; i++) {
    for (int j = 1; j <= 601; j++) {
      ans = max(ans, dp[i][j]);
    }
  }
  cout << ans << endl;
}
