#include <bits/stdc++.h>
#pragma optimization_level 3
using namespace std;
long double TL = 1.0;
bool is_tl = 0;
long long CALLS = 0;
inline bool IS() {
  if (++CALLS == 1000) {
    CALLS = 0;
    is_tl |= clock() > (TL - 0.1) * CLOCKS_PER_SEC;
  }
  return is_tl;
}
template <typename T1, typename T2>
inline void amin(T1 &a, T2 b) {
  if (a > b) a = b;
}
template <typename T1, typename T2>
inline void amax(T1 &a, T2 b) {
  if (a < b) a = b;
}
template <typename T>
inline void print(T &a) {
  for (auto &U : a) cout << U << ' ';
  cout << '\n';
}
const long long N = 1e6 + 7, NS = 1e3 + 7, lg = 20, sq = 550, inf = 1e18 + 7,
                mod = 1e9 + 7, SM = 1e2 + 7;
const long double eps = 1e-9;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
void solve() {
  long long n, p;
  cin >> n >> p;
  vector<long long> a(n), res;
  for (long long i = 0; i < n; i++) cin >> a[i];
  sort((a).begin(), (a).end());
  long long mn = 0;
  for (long long i = 0; i < n; i++) mn = max(mn, a[i] - i);
  long long l = mn, r = 1e9 + 1;
  while (r - l > 1) {
    long long x = (l + r) / 2;
    bool f = 1;
    for (long long i = 0; i < n; i++) {
      long long cnt =
          upper_bound((a).begin(), (a).end(), i + x) - a.begin() - i;
      if (cnt <= 0 || cnt % p == 0) {
        f = 0;
        break;
      }
    }
    if (f)
      l = x;
    else
      r = x;
  }
  long long x = mn;
  bool f = 1;
  for (long long i = 0; i < n; i++) {
    long long cnt = upper_bound((a).begin(), (a).end(), i + x) - a.begin() - i;
    if (cnt <= 0 || cnt % p == 0) {
      f = 0;
      break;
    }
  }
  if (!f)
    cout << 0 << '\n';
  else {
    for (long long i = mn; i <= l; i++) res.push_back(i);
    cout << res.size() << '\n';
    print(res);
  }
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  solve();
}
