#include <bits/stdc++.h>
#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
using namespace std;
const long long N = 2e5 + 5;
const long long mod = 998244353;
const long long INF = 1e18;
const int INFi = 0x7f7f7f7f;
long long test = 1, n, p, a[N], y[N];
multiset<long long> second;
void solve() {
  cin >> n >> p;
  for (int i = 0; i < n; i++) cin >> a[i];
  sort(a, a + n);
  vector<long long> ans;
  long long st = 0, val = 0, ct = 0;
  for (int i = 0; i < n; i++) {
    st = max(st, a[i] - i);
  }
  for (int j = 0, i = 0, x = st; j < n; j++, x++) {
    while (i < n and a[i] <= x) i++, ct++;
    y[j] = ct % p;
    second.insert(ct % p);
    ct--;
  }
  for (int j = 0; j < n; j++) {
    if (second.find(val) == second.end()) ans.push_back(st + j);
    auto it = second.lower_bound(y[j]);
    second.erase(it);
    second.insert(val);
    val = (val - 1 + p) % p;
  }
  cout << ans.size() << "\n";
  for (auto it : ans) cout << it << " ";
  cout << "\n";
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cout << fixed;
  cout << setprecision(10);
  ;
  for (int i = 1; i <= test; i++) {
    solve();
  }
}
