#include <bits/stdc++.h>
using namespace std;
const long long M = 1e9 + 7;
long long pmp(long long x, long long n) {
  long long a = 1;
  while (n > 0) {
    if (n & 1) a = (a * x) % M;
    x = (x * x) % M;
    n = n >> 1;
  }
  return a;
}
void solve() {
  long long n, p;
  cin >> n >> p;
  vector<long long> a(n);
  long long mx = 0;
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
    mx = max(mx, a[i]);
  }
  vector<long long> b(2 * n + 1, 0);
  for (long long i = 0; i < n; i++) {
    b[max(0LL, a[i] - mx + n)]++;
  }
  for (long long i = 0; i < 2 * n; i++) b[i + 1] += b[i];
  for (long long i = 0; i < 2 * n + 1; i++) b[i] = (mx - n + i - b[i]);
  vector<long long> ans;
  vector<long long> r(p, 0);
  for (long long i = 0; i < n; i++) r[((b[i] % p) + p) % p]++;
  long long lo = 0;
  long long hi = n - 1;
  while (hi <= 2 * n) {
    long long rr = (((lo + mx - n) % p) + p) % p;
    if (r[rr] == 0) {
      ans.push_back(lo + mx - n);
    }
    r[((b[lo++] % p) + p) % p]--;
    r[((b[++hi] % p) + p) % p]++;
  }
  cout << ans.size() << endl;
  for (long long i = 0; i < ans.size(); i++) cout << ans[i] << " ";
  cout << endl;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t;
  t = 1;
  while (t--) {
    solve();
  }
  cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC
       << "ms\n";
  return 0;
}
