#include <bits/stdc++.h>
using namespace std;
bool isgood(long long int x, long long int p, vector<long long int> &v) {
  long long int r = 0;
  long long int n = ((long long int)v.size());
  for (long long int l = 0; l < (n); l++) {
    while (r < n && v[r] - x <= 0) {
      r++;
    }
    if ((r - l) % p == 0) return false;
    x++;
  }
  return true;
}
bool ispositive(long long int x, long long int p, vector<long long int> &v) {
  long long int r = 0;
  long long int n = ((long long int)v.size());
  for (long long int l = 0; l < (n); l++) {
    while (r < n && v[r] - x <= 0) {
      r++;
    }
    if ((r - l) == 0) return false;
    x++;
  }
  return true;
}
void solve() {
  long long int n, p;
  cin >> n >> p;
  vector<long long int> v(n);
  for (long long int i = 0; i < (n); i++) cin >> v[i];
  sort((v).begin(), (v).end());
  long long int mine = v.back() - n + 1;
  long long int maxe = v.back();
  long long int l = mine - 1, r = maxe + 1;
  while (l + 1 < r) {
    long long int mid = (l + r) / 2;
    if (ispositive(mid, p, v)) {
      r = mid;
    } else {
      l = mid;
    }
  }
  mine = r;
  vector<long long int> ans;
  l = mine;
  r = maxe + 1;
  while (l < r) {
    long long int mid = (l + r) / 2;
    if (isgood(mid, p, v)) {
      l = mid + 1;
    } else {
      r = mid;
    }
  }
  maxe = l - 1;
  for (long long int i = mine; i < (maxe + 1); i++) ans.push_back(i);
  sort((ans).begin(), (ans).end());
  cout << ((long long int)ans.size()) << endl;
  for (auto it = ans.begin(); it != ans.end(); it++) {
    cout << *it << " ";
  }
  cout << endl;
  ;
}
int main() {
  long long int t;
  t = 1;
  while (t--) solve();
}
