#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 3;
const int mod = 1e9 + 7;
const int inf = 2e9;
const double pi = acos(-1.0);
const double eps = 1e-13;
struct unionset {
  int fat[1003], len;
  void init(int x) {
    len = x;
    for (int i = 0; i < x; i++) fat[i] = i;
    return;
  }
  int getf(int x) {
    if (fat[x] == x) return x;
    return fat[x] = getf(fat[x]);
  }
  void un(int x, int y) {
    fat[getf(y)] = getf(x);
    return;
  }
};
struct tree_array {
  int c[1003];
  int v[1003], len;
  int get_low(int x) { return x & (-x); }
  void init(int x) {
    len = x;
    for (int i = 0; i < x; i++) c[i] = v[i] = 0;
    return;
  }
  void add(int x, int value) {
    v[x] += value;
    while (x <= len) {
      c[x] += value;
      x += get_low(x);
    }
    return;
  }
  int sum(int x) {
    int ans = 0;
    while (x > 0) {
      ans += c[x];
      x -= get_low(x);
    }
    return ans;
  }
};
long long int mult(long long int a, long long int b, long long int c) {
  long long int ans = 0, temp = a % c;
  while (b) {
    if (b & 1)
      if ((ans += temp) > c) ans -= c;
    temp <<= 1;
    while (temp > c) temp -= c;
    b >>= 1;
  }
  return ans;
}
long long pow_mod(long long a, long long b, long long c) {
  long long ans = 1, tmp = a;
  while (b) {
    if (b & 1) ans = mult(ans, tmp, c);
    tmp = mult(tmp, tmp, c);
    b >>= 1;
  }
  return ans;
}
int pow_mod(int a, int b, int c) {
  long long ans = 1, tmp = a % c;
  while (b) {
    if (b & 1) ans = ans * tmp % c;
    tmp = tmp * tmp % c;
    b >>= 1;
  }
  return ans;
}
long long gcd(long long a, long long b) { return !b ? a : gcd(b, a % b); }
vector<int> int2vector(int a[], int len) {
  vector<int> tmp(a, a + len / sizeof(int));
  return tmp;
}
int have[30003];
int dp[30003][1000] = {0};
int main() {
  int n, d;
  memset(have, 0, sizeof(have));
  scanf("%d%d", &n, &d);
  for (int i = 0; i < n; i++) {
    int tmp;
    scanf("%d", &tmp);
    have[tmp]++;
  }
  int ans = 1;
  if (have[d]) ans += have[d];
  dp[d][500] = ans;
  for (int i = d; i < 30001; i++) {
    for (int j = 0; j < 1000; j++)
      if (dp[i][j]) {
        int a = d + j - 500;
        int b = dp[i][j];
        ans = max(b, ans);
        for (int k = -1; k < 2; k++)
          if (i + k + a < 30001 && a + k > 0) {
            int ttt = i + k + a;
            dp[ttt][a + k - d + 500] =
                max(dp[ttt][a + k - d + 500], b + have[ttt]);
          }
      }
  }
  cout << ans - 1 << endl;
  return 0;
}
