#include <bits/stdc++.h>
using namespace std;
long long freq[30005] = {0};
long long n, d;
long long dp[30005][500];
long long maxGems(long long currPos, long long prevJump) {
  long long _prevJump = prevJump - d + 250;
  if (currPos >= 30001) {
    return 0;
  }
  if (dp[currPos][_prevJump] != -1) {
    return dp[currPos][_prevJump];
  }
  long long op1 = INT_MIN, op2 = INT_MIN, op3 = INT_MIN;
  op1 = maxGems(currPos + prevJump, prevJump);
  op3 = maxGems(currPos + prevJump + 1, prevJump + 1);
  if (prevJump - 1) {
    op2 = maxGems(currPos + prevJump - 1, prevJump - 1);
  }
  return dp[currPos][_prevJump] = max({op1, op2, op3}) + freq[currPos];
}
signed main() {
  memset(dp, -1, sizeof(dp));
  cin >> n >> d;
  for (long long i = 0; i < n; i++) {
    long long x;
    cin >> x;
    freq[x]++;
  }
  cout << maxGems(d, d) << endl;
}
