#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7;
long long n, p;
long long a[N];
vector<long long> ans;
bool can(long long x) {
  for (int i = 0; i < n; i++) {
    if (x < a[i]) return 0;
    x++;
  }
  return 1;
}
long long getM() {
  long long ret = 1e9 + 1;
  long long L = 1, R = 1e9;
  while (L <= R) {
    long long mid = (L + R) >> 1;
    if (can(mid)) {
      R = mid - 1;
      ret = mid;
    } else {
      L = mid + 1;
    }
  }
  return ret;
}
unordered_map<int, bool> bads;
bool mods[N];
map<int, vector<int> > mps;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> p;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a, a + n);
  long long L = getM();
  reverse(a, a + n);
  long long R = getM();
  reverse(a, a + n);
  long long realR = R;
  for (int j = L; j < R; j++) {
    for (int i = 0; i < n; i++) {
      int poss = j + n - a[i];
      poss = max(0, poss);
      poss = min((int)n, poss);
      int k = poss - (n - i - 1);
      int rem = min(R - L, n - poss - 1);
      int rem1 = n - poss;
      int rmk = p - (k + p - 1) % p;
      if (rmk <= rem1 + 1) {
        realR = min(realR, L + rmk);
      }
      k += rmk;
      for (int l = rmk - 1; l < R - L && l <= rem1; l += p) {
        if ((k - 1) % p == 0) {
          bads[L + l] = 1;
          mps[L + l].push_back(l % p);
          break;
        }
      }
    }
    break;
  }
  for (int i = L; i < realR; i++) {
    for (auto j : mps[i]) {
      mods[j] = 1;
    }
    if (!bads[i] && !mods[(i - L) % p]) {
      ans.push_back(i);
    }
  }
  cout << (int)ans.size() << "\n";
  for (int i = 0; i < (int)ans.size(); i++) {
    cout << ans[i] << " ";
  }
  return 0;
}
