#include <bits/stdc++.h>
using namespace std;
int N, d, a, b, c, xtra, off;
int C[30100], P[30100];
int dp[30100][888];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> N >> d;
  for (int I = 0; I < N; I++) {
    cin >> P[I];
    C[P[I]]++;
  }
  off = 300 - d;
  if (off >= 0) off = 0;
  for (int I = 30000; I >= 0; I--) {
    if (d > 301) {
      for (int len = d - 300; len < d + 300; len++) {
        a = len - 1;
        b = len;
        c = len + 1;
        dp[I][len + off] += C[I];
        if (I + len >= 30100) continue;
        xtra = 0;
        if (a > 0) xtra = max(xtra, dp[I + a][a + off]);
        xtra = max(xtra, dp[I + b][b + off]);
        if (I + c < 30100) xtra = max(xtra, dp[I + c][c + off]);
        dp[I][len + off] += xtra;
      }
    } else {
      for (int len = max(1, d - 300); len < d + 300; len++) {
        a = len - 1;
        b = len;
        c = len + 1;
        dp[I][len] += C[I];
        if (I + len >= 30100) continue;
        xtra = 0;
        if (a > 0) xtra = max(xtra, dp[I + a][a]);
        xtra = max(xtra, dp[I + b][b]);
        if (I + c < 30100) xtra = max(xtra, dp[I + c][c]);
        dp[I][len] += xtra;
      }
    }
  }
  if (d > 301)
    cout << dp[d][d + off] << endl;
  else
    cout << dp[d][d] << endl;
}
