#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1e9 + 7;
const long long int inf = 2e9 + 5;
double PI = 3.14159265358979323846;
const int N = 30005;
int dp[N][500];
int n, d;
int a[N];
int lastGem = 0;
int go(int dist, int now) {
  if (now > lastGem) return 0;
  if (dp[now][dist - d + 250] != -1) {
    return dp[now][dist - d + 250];
  }
  int ans = 0;
  ans =
      max(a[now] + go(dist, now + dist), a[now] + go(dist + 1, now + dist + 1));
  if (dist > 1) {
    ans = max(ans, a[now] + go(dist - 1, now + dist - 1));
  }
  return dp[now][dist - d + 250] = ans;
}
void solve() {
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < 500; j++) {
      dp[i][j] = -1;
    }
  }
  cin >> n >> d;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    lastGem = max(lastGem, x);
    a[x] += 1;
  }
  int ans = go(d, d);
  cout << ans << "\n";
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  solve();
  return 0;
}
