#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 7;
const int inf = INT_MAX;
const long long inff = 1e18;
const long long mod = 1e9 + 7;
long long n, p;
long long a[maxn];
bool check(long long X) {
  long long r = 0;
  for (long long i = 1; i <= n; i++) {
    while (r < n && a[r + 1] <= X + (i - 1)) r++;
    if (r < i) return 0;
  }
  return 1;
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> p;
  for (long long i = 1; i <= n; i++) cin >> a[i];
  sort(a + 1, a + n + 1);
  long long L = 0, R = 1000000000;
  while (R - L > 1) {
    long long M = (L + R) >> 1;
    if (check(M))
      R = M;
    else
      L = M;
  }
  long long l = a[n] - n + 1, r = a[n] - n + p;
  vector<long long> v;
  long long tmp = 0;
  for (long long i = a[n] - n - 1; i <= a[n] + n + 1; i++) {
    while (tmp < n && a[tmp + 1] <= i) tmp++;
    long long tmp2 = i - tmp % p;
    if (tmp2 < l)
      continue;
    else if (i - ((tmp2 - l) % p + l) + 1 > n)
      continue;
    else
      v.push_back((tmp2 - l) % p + l);
  }
  sort((v).begin(), (v).end());
  reverse((v).begin(), (v).end());
  vector<long long> ans;
  while (v.back() < l) v.pop_back();
  for (long long i = l; i <= r; i++) {
    long long cnt = 0;
    while (((long long)(v).size()) > 0 && v.back() == i) {
      cnt++;
      v.pop_back();
    }
    if (!cnt && i >= R) ans.push_back(i);
  }
  cout << ((long long)(ans).size()) << '\n';
  for (long long i : ans) cout << i << ' ';
}
