#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long int n, p, arr[200005], ind, f, move, low;
  set<int> st;
  vector<int> ans;
  cin >> n >> p;
  for (int i = 0; i < n; i++) cin >> arr[i];
  sort(arr, arr + n);
  low = arr[0];
  for (int i = 0, cur = low; i < n; i++) {
    if (arr[i] <= cur) {
      cur++;
    } else {
      low += arr[i] - cur;
      cur = arr[i] + 1;
    }
  }
  for (int move = 0, x = arr[n - 1]; x >= low; x--) {
    ind = upper_bound(arr, arr + n, x) - arr;
    if (ind >= p) {
      st.insert(move + ind - p);
    }
    f = 0;
    if (!st.empty() && st.find(move) != st.end()) {
      st.erase(move);
      f = 1;
    }
    if (f == 1 || n - move >= p) {
      move++;
      continue;
    }
    ans.push_back(x);
    move++;
  }
  cout << ans.size() << endl;
  for (int i = ans.size() - 1; i >= 0; i--) {
    cout << ans[i] << " ";
  }
  cout << endl;
}
int main() {
  int t;
  t = 1;
  for (int q = 0; q < t; q++) {
    solve();
  }
  return 0;
}
