#include <bits/stdc++.h>
using namespace std;
template <typename T>
string to_string(const vector<T>& vc, int w) {
  if (vc.empty()) return "";
  if (w + 1 == vc.size()) return to_string(vc[w]);
  return to_string(vc[w]) + "," + to_string(vc, w + 1);
}
template <typename T>
string to_string(const vector<T>& vc) {
  return "{" + to_string(vc, 0) + "}";
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
class DebugStream {
} LOG;
template <typename T>
DebugStream& operator<<(DebugStream& s, const T&) {
  return s;
}
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
const int maxN = 1e5 + 9, maxV = 1e6 + 9, MOD = 1e9 + 7, SQ = 335, lg = 20,
          bs = 29;
int n, p;
long long arr[maxN];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> p;
  for (int i = 0; i < n; i++) cin >> arr[i];
  sort(arr, arr + n);
  int strt = 0;
  for (int i = 0; i < n; i++) strt = max(strt, int(arr[i]) - i);
  vector<int> dstr(n), frq(p), spcs(n);
  for (int i = 0; i < n; i++) {
    long long w = max(0LL, arr[i] - strt);
    assert(w < n);
    dstr[w]++;
  }
  for (int i = n - 1, suma = 0; i >= 0; i--) {
    int spc = n - i - suma;
    assert(spc >= dstr[i]);
    for (int j = 0; j < dstr[i]; j++) frq[(spc - j) % p]++;
    spcs[i] = spc;
    suma += dstr[i];
  }
  vector<int> ans;
  for (int i = 0, suma = 0; i < n; i++) {
    int spc = spcs[i];
    for (int j = 0; j < dstr[i]; j++) frq[(spc - j) % p]--;
    suma += dstr[i];
    if (suma >= p) break;
    if (!frq[(-i % p + p) % p]) ans.push_back(strt + i);
  }
  cout << ans.size() << '\n';
  for (auto el : ans) cout << el << ' ';
  cout << '\n';
}
