#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, p;
  cin >> n >> p;
  int aray[n];
  for (int i = 0; i < n; i++) cin >> aray[i];
  sort(aray, aray + n);
  int val = 0;
  for (int i = 0; i < n; i++) val = max(aray[i] - i, val);
  int curr[n];
  for (int i = 0; i < n; i++) {
    int num = aray[i] - val;
    num = max(num, 0);
    num = i - num + 1;
    curr[i] = num;
  }
  int limit = n + 1;
  for (int i = p - 1; i < n; i += p) {
    int num = (i + 1) - num;
    limit = min(limit, (i + 1) - curr[i]);
  }
  int poss[limit];
  for (int i = 0; i < limit; i++) poss[i] = 1;
  for (int i = 0; i < n; i++) {
    int num = curr[i] % p;
    if (num == 0) poss[0] = 0;
    num = p - num;
    int value = curr[i] + num;
    while (value <= (i + 1)) {
      if ((value - curr[i]) >= limit) break;
      poss[value - curr[i]] = 0;
      value += p;
    }
  }
  vector<int> v;
  for (int i = 0; i < limit; i++) {
    if (poss[i]) v.push_back(i);
  }
  cout << v.size() << "\n";
  for (int i = 0; i < v.size(); i++) cout << v[i] + val << " ";
  cout << "\n";
  return 0;
}
