#include <bits/stdc++.h>
using namespace std;
long long ara[30010], dp[30010][502], b;
long long rock_climbing(long long dis, long long pos) {
  if (dis < 0 || dis > 30000 || (b + pos) <= 0) return 0;
  long long &p = dp[dis][pos];
  if (p != -1) return p;
  p = 0;
  p = max(p, rock_climbing(dis + pos + b, pos));
  p = max(p, rock_climbing(dis + pos + b + 1, pos + 1));
  p = max(p, rock_climbing(dis + pos + b - 1, pos - 1));
  p += ara[dis];
  return p;
}
int main() {
  long long a;
  cin >> a >> b;
  for (long long i = 0; i < a; i++) {
    long long p;
    cin >> p;
    ara[p]++;
  }
  memset(dp, -1, sizeof(dp));
  cout << rock_climbing(b, 0);
}
