#include <bits/stdc++.h>
using namespace std;
long long int gems[30005];
long long int dp[30005][600];
int main() {
  long long int n, d, num, ans = 0;
  cin >> n >> d;
  for (int i = 0; i < n; i++) {
    cin >> num;
    gems[num]++;
  }
  for (int i = 0; i <= 30000; i++) {
    for (int j = 0; j <= 600; j++) {
      dp[i][j] = -1;
    }
  }
  dp[0][300] = gems[0];
  for (int i = d; i <= 30000; i++) {
    for (int j = 1; j <= 600; j++) {
      int jj = j - 300 + d;
      if (jj <= 0) continue;
      if (i - jj + 1 >= 0) {
        if (dp[i - jj + 1][j - 1] >= 0)
          dp[i][j] = max(dp[i][j], gems[i] + dp[i - jj + 1][j - 1]);
      }
      if (i - jj >= 0) {
        if (dp[i - jj][j] >= 0)
          dp[i][j] = max(dp[i][j], gems[i] + dp[i - jj][j]);
      }
      if (i - jj - 1 >= 0) {
        if (dp[i - jj - 1][j + 1] >= 0)
          dp[i][j] = max(dp[i][j], gems[i] + dp[i - jj - 1][j + 1]);
      }
      ans = max(ans, dp[i][j]);
    }
  }
  cout << ans;
  return 0;
}
