#include <bits/stdc++.h>
using namespace std;
using ill = long long;
class solution {
 public:
  void solve() {
    ill n, p;
    cin >> n >> p;
    vector<ill> a(n, 0);
    for (ill i = 0; i <= n - 1; ++i) cin >> a[i];
    sort(a.begin(), a.end());
    ill minX = -1;
    for (ill i = 0; i <= n - 1; ++i) minX = max(minX, a[i] - i);
    auto check = [&](ill x) {
      ill now = 0;
      for (ill i = 0; i <= n - 1; ++i) {
        while (now <= n - 1 && a[now] <= x) ++now;
        if ((now - i) % p == 0) return false;
        ++x;
      }
      return true;
    };
    ill l = minX - 1, r = 1e9;
    while (l + 1 < r) {
      ill mid = (l + r) / 2;
      if (check(mid) == true)
        l = mid;
      else
        r = mid;
    }
    cout << l - minX + 1 << '\n';
    for (ill x = minX; x <= l; ++x) {
      if (x > minX) cout << ' ';
      cout << x;
    }
    cout << '\n';
  }
};
int main() {
  ios_base::sync_with_stdio(false);
  std::cin.tie(NULL);
  std::cout.tie(NULL);
  solution sln1;
  sln1.solve();
  cout.flush();
  return 0;
}
