#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
int n, p, a[maxn];
int mark[maxn];
int val[maxn], ans;
struct Data {
  int p, limit;
  Data() {}
  Data(int p, int limit) { this->p = p, this->limit = limit; }
} seq[maxn];
int cnt;
set<int> Set;
bool cmp(Data a, Data b) { return a.limit < b.limit; }
int main() {
  scanf("%d%d", &n, &p);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  sort(a + 1, a + n + 1);
  int Low = a[n], Up = 0;
  for (int i = 1; i <= n; i++) {
    Up = max(Up, a[i] - i);
    mark[((a[i] - i) % p + p) % p] = a[i];
    if (i % p == 0) Low = min(Low, a[i]);
  }
  for (int i = 0; i < p; i++)
    if (mark[i]) seq[++cnt] = Data(i, mark[i]);
  sort(seq + 1, seq + cnt + 1, cmp);
  int first = 1;
  for (int x = Up + 1; x % p != 0 && x < Low; x++) {
    while (first <= cnt && seq[first].limit <= x) mark[seq[first++].p] = 0;
    if (!mark[x % p]) val[++ans] = x;
  }
  for (int i = 0; i < p; i++)
    if (!mark[i]) Set.insert(i);
  int x = (Up / p + 1) * p, X = (Low - 1) / p * p;
  set<int>::iterator it;
  while (x < X) {
    int now = x - 1;
    it = Set.begin();
    while (it != Set.end()) {
      int tmp = *it;
      while (first <= cnt && seq[first].limit <= x + tmp) {
        mark[seq[first].p] = 0, Set.insert(seq[first++].p);
      }
      it = Set.upper_bound(now - x);
      while (it != Set.end()) {
        val[++ans] = now = x + *it;
        if (*it == tmp) break;
        *it++;
      }
      it++;
    }
    x += p;
  }
  while (x < Low) {
    while (first <= cnt && seq[first].limit <= x) mark[seq[first++].p] = 0;
    if (!mark[x % p]) val[++ans] = x;
    x++;
  }
  printf("%d\n", ans);
  if (ans) {
    for (int i = 1; i < ans; i++) printf("%d ", val[i]);
    printf("%d\n", val[ans]);
  }
  return 0;
}
