#include <bits/stdc++.h>
using namespace std;
int n, d;
int p[30001];
int cache[30001][501];
int main() {
  cin >> n >> d;
  memset(p, 0, sizeof(p));
  memset(cache, 0, sizeof(cache));
  for (int i = 0; i < n; i++) {
    int t;
    cin >> t;
    p[t]++;
  }
  for (int i = 0; i <= 500; i++) {
    cache[30000][i] = p[30000];
  }
  for (int i = 29999; i >= 0; i--) {
    for (int j = d - 250; j <= d + 250; j++) {
      if (j <= 0) continue;
      int maxv = 0;
      if (j == 1) {
        for (int t = j; t <= j + 1; t++) {
          if (i + t > 30000) continue;
          maxv = max(maxv, cache[i + t][t - (d - 250)]);
        }
      } else {
        for (int t = j - 1; t <= j + 1; t++) {
          if (i + t > 30000) continue;
          maxv = max(maxv, cache[i + t][t - (d - 250)]);
        }
      }
      cache[i][j - (d - 250)] = p[i] + maxv;
    }
  }
  cout << cache[d][250];
  return 0;
}
