#include <bits/stdc++.h>
using namespace std;
const int maxx = 1000001;
void solve() {
  int n, p;
  cin >> n >> p;
  int arr[n];
  map<int, int> upd;
  for (int i = 0; i < n; i++) cin >> arr[i];
  sort(arr, arr + n);
  int L, R;
  int l = arr[0], r = arr[n - 1], bst = arr[n - 1] + 1;
  while (l <= r) {
    int mid = (l + r) >> 1;
    upd.clear();
    for (int i = 0; i < n; i++) {
      upd[0]--;
      upd[max(0, arr[i] - mid)]++;
    }
    bool f = true;
    for (int i = 0; i < n; i++) {
      upd[i] += upd[i - 1];
      int val = n - i + upd[i];
      if (val <= 0) f = false;
    }
    if (f) {
      bst = mid;
      r = mid - 1;
    } else
      l = mid + 1;
  }
  if (bst == arr[n - 1] + 1) {
    cout << 0 << '\n';
    return;
  }
  L = bst;
  l = L, r = arr[n - 1], bst = arr[n - 1] + 1;
  while (l <= r) {
    int mid = (l + r) >> 1;
    upd.clear();
    for (int i = 0; i < n; i++) {
      upd[0]--;
      upd[max(0, arr[i] - mid)]++;
    }
    bool f = false;
    for (int i = 0; i < n; i++) {
      upd[i] += upd[i - 1];
      if ((n - i + upd[i]) % p == 0) {
        f = true;
        break;
      }
    }
    if (f) {
      bst = mid;
      r = mid - 1;
    } else
      l = mid + 1;
  }
  R = bst;
  cout << R - L << '\n';
  for (int i = L; i < R; i++) cout << i << " ";
  cout << '\n';
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  ;
  int t = 1;
  while (t--) {
    solve();
  }
}
