#include <bits/stdc++.h>
int anz[100100];
int main(void) {
  std::vector<int> seq;
  int n, p;
  scanf("%d %d", &n, &p);
  int a;
  for (int i = 0; i < n; i++) {
    scanf("%d", &a);
    seq.push_back(a);
  };
  std::sort(seq.begin(), seq.end());
  int x = seq[0];
  int cnt = 0;
  std::priority_queue<std::pair<int, int>, std::vector<std::pair<int, int>>,
                      std::greater<std::pair<int, int>>>
      pq;
  int pos = 1;
  for (int i = 0; i < n; i++) {
    int tmp = x + i;
    auto it = std::upper_bound(seq.begin(), seq.end(), tmp);
    int an = it - seq.begin();
    an -= i;
    if (an % p == 0) {
      cnt++;
      if (it == seq.end()) pos = 0;
    };
    if (it != seq.end()) {
      int val = *it - i;
      pq.push({val, i});
    };
    anz[i] = an;
  };
  std::vector<int> erg;
  while (pos && pq.size()) {
    std::pair<int, int> akt = pq.top();
    pq.pop();
    int tt = akt.first;
    int cpr = cnt;
    while (akt.first == tt) {
      int tmp = akt.first + akt.second;
      auto it = std::upper_bound(seq.begin(), seq.end(), tmp);
      int an = it - seq.begin();
      an -= akt.second;
      if (anz[akt.second] % p == 0) cnt--;
      if (an % p == 0) {
        cnt++;
        if (it == seq.end()) pos = 0;
      };
      if (it != seq.end()) {
        int val = *it - akt.second;
        pq.push({val, akt.second});
      };
      anz[akt.second] = an;
      if (!pq.size() || pq.top().first != tt) break;
      akt = pq.top();
      pq.pop();
    };
    if (!cpr) {
      for (int j = x; j < tt; j++) {
        erg.push_back(j);
      };
    };
    x = tt;
  };
  printf("%d\n", erg.size());
  for (auto i : erg) {
    printf("%d ", i);
  };
  puts("");
  return 0;
};
