#include <bits/stdc++.h>
using namespace std;
const int buf_size = 1e5 + 5;
char buf[buf_size], *S, *T;
inline char gc() {
  if (S == T) T = (S = buf) + fread(buf, 1, buf_size, stdin);
  return S != T ? *(S++) : EOF;
}
inline int in() {
  int x = 0, f = 1;
  char c = gc();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = gc();
  }
  while (c >= '0' && c <= '9') x = x * 10 + c - 48, c = gc();
  return x * f;
}
const int N = 1e5 + 5;
int n, p, x;
int a[N];
int s[N], g[N];
int ans[N], ac;
int mark[N];
int main() {
  n = in(), p = in();
  for (int i = 1; i <= n; i++) a[i] = in();
  sort(a + 1, a + n + 1);
  int st = a[n] - n + 1, j = 1;
  for (int i = 1; i <= n; i++) {
    if (a[i] < st)
      s[1]++;
    else
      s[a[i] - st + 1]++;
  }
  for (int i = 1; i <= n; i++) s[i] += s[i - 1];
  for (int i = 1; i <= n; i++) {
    mark[((s[i] - i) % p + p) % p]++;
  }
  for (int i = 1; i <= p; i++) {
    if (i + st - 1 > 0 && !mark[(p - i % p) % p]) ans[++ac] = i + st - 1;
    mark[((s[i] - i) % p + p) % p]--;
  }
  cout << ac << endl;
  for (int i = 1; i <= ac; i++) printf("%d ", ans[i]);
  return 0;
}
