#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0, neg = 1;
  char op = getchar();
  while (!isdigit(op)) {
    if (op == '-') neg = -1;
    op = getchar();
  }
  while (isdigit(op)) {
    x = 10 * x + op - '0';
    op = getchar();
  }
  return neg * x;
}
inline void print(int x) {
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  if (x >= 10) print(x / 10);
  putchar(x % 10 + '0');
}
int mp[30007];
int dp[30007][507];
int main() {
  ios::sync_with_stdio(false);
  int n, d, temp = 0, ans = 0;
  memset(mp, 0, sizeof(mp));
  memset(dp, -1, sizeof(dp));
  cin >> n >> d;
  for (int i = 1; i <= n; ++i) {
    cin >> temp;
    ++mp[temp];
  }
  dp[d][250] = mp[d];
  for (int x = d; x <= 30000; ++x) {
    for (int i = 0; i <= 500; ++i) {
      int next = x - d - i + 250;
      if (next < 0 || next >= x) continue;
      for (int y = -1; y <= 1; ++y) {
        if (i + y > 0 && dp[next][i + y] != -1)
          dp[x][i] = max(dp[next][i + y] + mp[x], dp[x][i]);
      }
      ans = max(ans, dp[x][i]);
    }
  }
  cout << ans << endl;
  return 0;
}
