#include <bits/stdc++.h>
using namespace std;
int n, d;
int dp[30004][505];
int offset = 250;
int v[30004];
int rec(int x, int prev) {
  if (x > 30000) return 0;
  int t = prev + offset - d;
  if (dp[x][t] != -1) return dp[x][t];
  dp[x][t] = v[x];
  if (prev > 1) {
    dp[x][t] = max(dp[x][t], v[x] + rec(x + prev - 1, prev - 1));
  }
  dp[x][t] = max(dp[x][t], v[x] + rec(x + prev, prev));
  dp[x][t] = max(dp[x][t], v[x] + rec(x + prev + 1, prev + 1));
  return dp[x][t];
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> d;
  memset(dp, -1, sizeof(dp));
  memset(v, 0, sizeof(v));
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    v[x]++;
  }
  cout << rec(d, d);
  return 0;
}
