#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
const int N = 1e5 + 5;
int n, p, a[N];
vector<int> r;
map<int, int> cnt;
bool Never_give_up() {
  scanf("%d%d", &n, &p);
  for (int i = 0; i < n; ++i) scanf("%d", a + i);
  sort(a, a + n);
  int s = 0;
  for (int i = 0; i < n; ++i) s = max(s, a[i] - i);
  int l = 0, ss = s, take = 0;
  while (take < n) {
    while (l < n && a[l] <= ss) ++l;
    ++cnt[(l - take) % p];
    ++ss, ++take;
    r.push_back(l);
  }
  int cur = 0;
  vector<int> ans;
  for (int i = 0; i < r.size(); ++i) {
    if (!cnt[cur]) ans.push_back(s + i);
    --cnt[(r[i] - i) % p];
    cur = ((cur - 1) % p + p) % p;
    ++cnt[(cur + 1) % p];
  }
  printf("%d\n", ans.size());
  for (int i : ans) printf("%d ", i);
  return 0;
}
int main() {
  int t = 1;
  while (t--) {
    Never_give_up();
  }
  return 0;
}
