#include <bits/stdc++.h>
using namespace std;
const int64_t M1 = 998244353;
const int64_t M2 = 1000000007;
void solve() {
  int64_t n, p;
  cin >> n >> p;
  vector<int64_t> a(n);
  for (int64_t &x : a) cin >> x;
  sort(a.begin(), a.end());
  int64_t l = 0;
  for (int64_t i = 0; i < n; i++) l = max(l, a[i] - i);
  int64_t j = 0;
  int64_t r = a.back();
  for (int64_t i = 0; i <= n - p; i++) {
    while (j < n - 1 && j + 1 - i < p) j++;
    r = max(l, min(r, a[j] - i));
  }
  cout << r - l << "\n";
  while (l < r) cout << l++ << " ";
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  solve();
}
