#include <bits/stdc++.h>
using namespace std;
long long n, p;
vector<long long> a;
int get(long long x) { return upper_bound(a.begin(), a.end(), x) - a.begin(); }
bool can(long long x) {
  for (int i = 0, ThxDem = n; i < ThxDem; ++i) {
    long long tot = max(get(x + i) - i, 0);
    if (tot % p == 0) return 0;
  }
  return 1;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> p;
  a.resize(n);
  for (int i = 0, ThxDem = n; i < ThxDem; ++i) cin >> a[i];
  sort(a.begin(), a.end());
  long long mnx = 0;
  for (int i = 0, ThxDem = n; i < ThxDem; ++i) mnx = max(mnx, a[i] - i);
  long long l = mnx, r = a[n - 1];
  while (l <= r) {
    long long m = (l + r) / 2;
    if (can(m))
      l = m + 1;
    else
      r = m - 1;
  }
  cout << r + 1 - mnx << "\n";
  for (int i = mnx, ThxDem = r + 1; i < ThxDem; ++i) cout << i << " ";
  cout << "\n";
}
