#include <bits/stdc++.h>
using namespace std;
const char nl = '\n';
const int MAX_N = 100011;
const long long INF = (1 << 29) + 123;
const long long MOD = 1000000007;
const long double PI = 4 * atan((long double)1);
template <typename T>
bool ckmin(T& a, const T& b) {
  return a > b ? a = b, 1 : 0;
}
template <typename T>
bool ckmax(T& a, const T& b) {
  return b > a ? a = b, 1 : 0;
}
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
const int MX = 1 << 20;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, p;
  cin >> n >> p;
  int hi = 0;
  int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    ckmax(hi, a[i]);
  }
  sort(a, a + n);
  int z = 0;
  int res[p];
  for (int i = 0; i < p; i++) res[i] = 0;
  int off = 1;
  for (int i = (n)-1; i >= 0; i--) {
    if (a[i] <= hi - n)
      z++;
    else {
      res[((n - (a[i] - (hi - n)) - (n - i - 1)) % p + p) % p]++;
      ckmax(off, -((n - (a[i] - (hi - n)) - (n - i - 1))) + 1);
    }
  }
  vector<int> ans;
  for (int x = hi - n + off; x <= hi - 1; x++) {
    while (z < n && a[z] <= x) {
      res[((n - (a[z] - (hi - n)) - (n - z - 1)) % p + p) % p]--;
      z++;
    }
    if (z >= p) break;
    if (res[((hi - n - x) % p + p) % p]) continue;
    ans.push_back(x);
  }
  cout << (int)ans.size() << nl;
  for (auto& x : ans) cout << x << " ";
  cout << nl;
  return 0;
}
