#include <bits/stdc++.h>
using namespace std;
int n, p;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> p;
  vector<int> a(n);
  for (int x = 0; x < n; x++) cin >> a[x];
  sort(a.begin(), a.end());
  int v = 0;
  for (int x = 0; x < n; x++) {
    v = max(v, a[x] - x);
  }
  for (int x = 0; x < n; x++) {
    a[x] = max(0, a[x] - v);
  }
  vector<int> cnt(2e5 + 100);
  int lxd = n - 1;
  for (int x = n - 1; x >= 0; x--) {
    int sz1 = (x + 1 - a[x]);
    int sz2 = (x + 1);
    int l1 = p * ((sz1 + p - 1) / p);
    int l2 = p * (sz2 / p);
    cnt[l1 - sz1]++;
    cnt[l2 - sz1 + p]--;
    if (sz2 % p == 0) lxd = min(lxd, sz2 - sz1);
  }
  vector<int> asd;
  for (int x = 0; x < lxd; x++) {
    if (cnt[x] == 0) asd.push_back(v + x);
    if (x + p < 1e5 + 5) cnt[x + p] += cnt[x];
  }
  cout << asd.size() << endl;
  for (auto i : asd) cout << i << " ";
  return 0;
}
