#include <bits/stdc++.h>
using namespace std;
int n, d;
int p[30001], dp[30001][1000];
int main() {
  scanf("%d%d", &n, &d);
  for (int i = 0; i < n; i++) {
    int x;
    scanf("%d", &x);
    p[x]++;
  }
  for (int i = 0; i <= 30000; i++) {
    for (int j = 0; j < 1000; j++) {
      dp[i][j] = -1;
    }
  }
  dp[d][500] = p[d];
  for (int i = d + 1; i <= 30000; i++) {
    int m = max(0, i - d - 300), M = min(i - 1, i - d + 300);
    for (int j = m; j <= M; j++) {
      int x = i - j - d + 500;
      if (dp[j][x] != -1) dp[i][x] = max(dp[i][x], dp[j][x] + p[i]);
      if (dp[j][x - 1] != -1) dp[i][x] = max(dp[i][x], dp[j][x - 1] + p[i]);
      if (dp[j][x + 1] != -1) dp[i][x] = max(dp[i][x], dp[j][x + 1] + p[i]);
    }
  }
  int ans = 0;
  for (int i = 0; i <= 30000; i++) {
    for (int j = 0; j < 1000; j++) {
      ans = max(ans, dp[i][j]);
    }
  }
  cout << ans << endl;
}
