#include <bits/stdc++.h>
using namespace std;
int N, P;
set<int> OK[100005];
int A[100005], B[100005];
int Rt;
bool chk(int mnx) {
  for (int i = N; i >= 1; i--) {
    int ss = 1;
    for (int j = i - 1; j >= 1; j--) {
      if (A[j] == A[i])
        ss++;
      else
        break;
    }
    if (A[i] > (mnx + i - 1)) return 0;
    int rng = (A[i] <= mnx) ? N : N - (A[i] - mnx);
    rng -= (N - i);
    for (int j = i; j >= i - ss + 1; j--) {
      B[j] = rng;
      if (B[j] < 0) return 0;
      rng--;
    }
    i = (i - ss + 1);
  }
  return 1;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N >> P;
  for (int i = 1; i <= N; i++) cin >> A[i];
  sort(A + 1, A + 1 + N);
  int l = 0, r = 1e9 + 5;
  while (l + 1 < r) {
    int m = (l + r) / 2;
    if (chk(m))
      r = m;
    else
      l = m;
  }
  int mnx = r;
  int mxx = A[N];
  for (int i = N; i >= 1; i--) {
    int ss = 1;
    for (int j = i - 1; j >= 1; j--) {
      if (A[j] == A[i])
        ss++;
      else
        break;
    }
    int rng = (A[i] <= mnx) ? N : N - (A[i] - mnx);
    rng -= (N - i);
    for (int j = i; j >= i - ss + 1; j--) {
      B[j] = rng;
      rng--;
    }
    i = (i - ss + 1);
  }
  for (int i = 0; i <= N - 1; i++) {
    OK[i % P].insert(i);
  }
  Rt = N;
  for (int i = N; i >= 1; i--) {
    int r = B[i] % P;
    if (r) r = P - r;
    while (!OK[r].empty() && B[i] + (*OK[r].begin()) <= i) {
      OK[r].erase(OK[r].begin());
    }
    if (i % P == 0) Rt = min(Rt, i - B[i]);
  }
  vector<int> ans;
  for (int i = 0; i <= N - 1; i++) {
    if (i >= Rt) break;
    int r = i % P;
    if ((OK[r].find(i) != OK[r].end())) ans.push_back(mnx + i);
  }
  cout << (int)(ans.size()) << '\n';
  for (int ai : ans) cout << ai << ' ';
  cout << '\n';
  return 0;
}
