#include <bits/stdc++.h>
using namespace std;
int f[30001][601], n, d, i, a[30001], x;
int tinh(int i, int j) {
  if (i > 30000) return 0;
  if (f[i][j + 300] > -1) return f[i][j + 300];
  int kq = 0;
  kq = max(kq, a[i] + tinh(i + d + j, j));
  if (i + d + j > i) kq = max(kq, a[i] + tinh(i + d + j + 1, j + 1));
  if (i + d + j - 1 > i) kq = max(kq, a[i] + tinh(i + d + j - 1, j - 1));
  return f[i][j + 300] = kq;
}
int main() {
  cin >> n >> d;
  for (i = 1; i <= n; i++) {
    cin >> x;
    a[x]++;
  }
  memset(f, -1, sizeof(f));
  cout << tinh(d, 0);
}
