#include <bits/stdc++.h>
#pragma GCC optimize("O3")
const double PI = acos(-1.0);
using namespace std;
const double EPS = 1e-9;
const int N = 5e5 + 9;
int n, p, a[N];
bool ok(int x) {
  for (int i = 1; i <= n; i++) {
    if (x >= a[i])
      x++;
    else
      return 0;
  }
  return 1;
}
bool go(int x) {
  map<int, int> mp;
  for (int i = 1; i <= n; i++) {
    mp[x] = i;
    auto it = mp.lower_bound(a[i]);
    if (it != mp.end()) {
      auto t = *it;
      if (i - t.second + 1 >= p) return 0;
    }
    x++;
  }
  return 1;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> p;
  for (int i = 1; i <= n; i++) cin >> a[i];
  sort(a + 1, a + 1 + n);
  int l = 0, r = 1e9, mid, f = -1, s = -1;
  while (l < r) {
    mid = (l + r) / 2;
    if (ok(mid)) {
      f = mid;
      r = mid;
    } else
      l = mid + 1;
  }
  if (f == -1 || !go(f)) {
    cout << "0";
    return 0;
  }
  s = f;
  l = f, r = 1e9;
  while (l < r) {
    mid = (l + r + 1) / 2;
    if (go(mid)) {
      s = mid;
      l = mid;
    } else
      r = mid - 1;
  }
  cout << (s - f + 1) << endl;
  for (int i = f; i <= s; i++) cout << i << " ";
  return 0;
}
