#include <bits/stdc++.h>
using namespace std;
bool used[30000 + 5][605 + 5];
int memo[30000 + 5][605 + 5];
int v[30000 + 5];
int D;
int dp(int pos, int dx) {
  if (pos > 30000) return 0;
  if (used[pos][300 + dx]) return memo[pos][300 + dx];
  used[pos][300 + dx] = 1;
  int &dev = memo[pos][300 + dx] = 0;
  int L = D + dx;
  if (L - 1 > 0) dev = max(dev, v[pos] + dp(pos + L - 1, dx - 1));
  if (L > 0) dev = max(dev, v[pos] + dp(pos + L, dx));
  if (L + 1 > 0) dev = max(dev, v[pos] + dp(pos + L + 1, dx + 1));
  return dev;
}
int main() {
  int n;
  while (scanf("%d", &n) == 1) {
    scanf("%d", &D);
    memset(v, 0, sizeof(v));
    for (int i = 0; i < n; ++i) {
      int p;
      scanf("%d", &p);
      v[p]++;
    }
    memset(used, 0, sizeof(used));
    for (int i = 30000; i >= 0; --i) dp(i, 0);
    printf("%d\n", dp(D, 0));
  }
}
