#include <bits/stdc++.h>
using namespace std;
int dp[30005][605];
int n, d;
int a[30005];
int r;
int dfs(int pos, int offset) {
  if (pos > r) return 0;
  if (dp[pos][offset] >= 0) return dp[pos][offset];
  int res = 0;
  for (int i = 0; i < 3; i++) {
    int newoff = offset + i - 1;
    if (d + (300 - newoff) > 0) {
      res = max(res, dfs(pos + d + (300 - newoff), newoff));
    }
  }
  return dp[pos][offset] = res + a[pos];
}
int main() {
  cin >> n >> d;
  memset(dp, -1, sizeof(dp));
  memset(a, 0, sizeof(a));
  r = -1;
  for (int i = 0; i < n; i++) {
    int tmp;
    cin >> tmp;
    a[tmp]++;
    r = max(r, tmp);
  }
  cout << dfs(d, 300) << endl;
  return 0;
}
