#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int base = 250;
int f[30010][510];
int a[N];
int main() {
  ios::sync_with_stdio(false);
  int n, d;
  cin >> n >> d;
  int i, j;
  for (i = 1; i <= n; i++) {
    int x;
    cin >> x;
    a[x]++;
  }
  memset(f, -0x3f, sizeof f);
  f[d][base] = a[d];
  int ans = 0;
  ans = a[d];
  for (i = d + 1; i <= 30000; i++) {
    for (j = 0; j <= 500; j++) {
      int last = i - (d + j - base);
      if (last < 0 || last >= i) continue;
      for (int k = -1; k <= 1; k++) {
        if (j + k > 0) {
          f[i][j] = max(f[i][j], f[last][j + k] + a[i]);
        }
      }
      ans = max(ans, f[i][j]);
    }
  }
  cout << ans << endl;
  return 0;
}
