#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long lcm(long long a, long long b) { return a * (b / gcd(a, b)); }
long long power(long long x, long long y, long long p) {
  long long res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) res = ((res % p) * (x % p)) % p;
    y = y >> 1;
    x = ((x % p) * (x % p)) % p;
  }
  return res;
}
int dp[30004][504];
int cnt[30004];
int calc(int x, int d, int diff) {
  if (x > 30000) return 0;
  if (dp[x][diff] != -1)
    return dp[x][diff];
  else {
    if (d + diff - 250 == 1)
      dp[x][diff] = cnt[x] + max(calc(x + d + (diff - 250), d, diff),
                                 calc(x + d + (diff - 250) + 1, d, diff + 1));
    else
      dp[x][diff] =
          cnt[x] + max(calc(x + d + (diff - 250) - 1, d, diff - 1),
                       max(calc(x + d + (diff - 250), d, diff),
                           calc(x + d + (diff - 250) + 1, d, diff + 1)));
  }
  return dp[x][diff];
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, d;
  cin >> n >> d;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    cnt[a] += 1;
  }
  memset(dp, -1, sizeof(dp));
  int ans = calc(d, d, 250);
  cout << ans;
  return 0;
}
