#include <bits/stdc++.h>
using namespace std;
int nxt() {
  int res;
  scanf("%d", &res);
  return res;
}
const int N = 30010;
int u[N];
const int M = 500;
int dp[N][M];
map<int, int> ans[N];
int mad = 0;
int solve(int pos, int d) {
  mad = max(mad, d);
  if (pos >= N) {
    return 0;
  }
  if (d < M) {
    if (dp[pos][d] != -1) {
      return dp[pos][d];
    }
  } else {
    if (ans[pos].count(d)) {
      return ans[pos][d];
    }
  }
  int ret = 0;
  ret = max(ret, u[pos] + solve(pos + d + 1, d + 1));
  ret = max(ret, u[pos] + solve(pos + d, d));
  if (d != 1) ret = max(ret, u[pos] + solve(pos + d - 1, d - 1));
  if (d < M) {
    dp[pos][d] = ret;
  } else {
    ans[pos][d] = ret;
  }
  return ret;
}
inline void solve() {
  memset(dp, 255, sizeof(dp));
  int n = nxt();
  int d = nxt();
  int a[n];
  for (int i = 0; i < n; ++i) {
    a[i] = nxt();
    u[a[i]]++;
  }
  int ans = solve(d, d);
  printf("%d\n", ans);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  srand(4524234);
  solve();
  return 0;
}
