#include <bits/stdc++.h>
using namespace std;
int dp[30005][600];
int vis[30005];
int main() {
  int n, d, temp;
  scanf("%d%d", &n, &d);
  memset(vis, 0, sizeof(vis));
  for (int i = 0; i < n; i++) {
    scanf("%d", &temp);
    vis[temp]++;
  }
  for (int i = 30000; i >= 0; i--) {
    for (int j = 0; j <= 600; j++) {
      dp[i][j] = vis[i];
      int temp = d + (j - 300);
      if (temp >= 1) {
        if (temp + i <= 30000) {
          dp[i][j] = (((dp[i][j]) > (dp[i + temp][j] + vis[i]))
                          ? (dp[i][j])
                          : (dp[i + temp][j] + vis[i]));
        }
        if (temp + i + 1 <= 30000) {
          dp[i][j] = (((dp[i][j]) > (dp[i + temp + 1][j + 1] + vis[i]))
                          ? (dp[i][j])
                          : (dp[i + temp + 1][j + 1] + vis[i]));
        }
        if (temp - 1 >= 1 && temp + i - 1 <= 30000) {
          dp[i][j] = (((dp[i][j]) > (dp[i + temp - 1][j - 1] + vis[i]))
                          ? (dp[i][j])
                          : (dp[i + temp - 1][j - 1] + vis[i]));
        }
      }
    }
  }
  printf("%d\n", dp[d][300]);
  return 0;
}
