#include <bits/stdc++.h>
using namespace std;
int n, d, Ans;
int a[(1 << 15)];
int dp[(1 << 15)][(1 << 10)], tr[(1 << 10)];
inline int DPDP(int xx, int yy) {
  if (yy < 0 || yy >= (1 << 10)) {
    return -1;
  }
  return dp[xx][yy];
}
int main() {
  scanf("%d%d", &n, &d);
  int tmp;
  for (int i = 0; i < n; i++) {
    scanf("%d", &tmp);
    a[tmp]++;
  }
  n = tmp;
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j < (1 << 10); j++) {
      dp[i][j] = -1;
    }
  }
  dp[d][(1 << 10) >> 1] = a[d];
  Ans = a[d];
  for (int i = 0; i < (1 << 10); i++) {
    tr[i] = d + i - ((1 << 10) >> 1);
  }
  for (int i = d + 1; i <= n; i++) {
    for (int j = 0; j < (1 << 10); j++) {
      if (tr[j] <= 0 || tr[j] > i) {
        continue;
      }
      int lst = i - tr[j];
      dp[i][j] = max(max(DPDP(lst, j), DPDP(lst, j - 1)), DPDP(lst, j + 1));
      if (dp[i][j] != -1) {
        dp[i][j] += a[i];
        Ans = max(Ans, dp[i][j]);
      }
    }
  }
  printf("%d\n", Ans);
  return 0;
}
