#include <bits/stdc++.h>
using namespace std;
const int N = (int)1e5 + 50, INF = (int)2e9;
int n, p;
int a[N];
int cnt[N];
set<int> S;
vector<pair<int, int> > era;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> p;
  int mn = 0, mx = (int)2e9;
  for (int i = 0; i < (n); ++i) cin >> a[i];
  sort(a, a + n);
  for (int i = 0; i < (n); ++i) {
    mn = max(mn, a[i] - i);
    int rem = ((a[i] - i - 1) % p + p) % p;
    cnt[rem]++;
    if ((i + 1) % p == 0)
      mx = min(mx, a[i]);
    else {
      era.push_back({a[i] - 1, rem});
    }
  }
  reverse(begin(era), end(era));
  for (int i = 0; i < p; i++)
    if (!cnt[i]) S.insert(i);
  int curx = mn - 1;
  vector<int> res;
  while (true) {
    int currem = curx % p;
    int nxtrem;
    if (S.empty())
      nxtrem = -1;
    else {
      auto it = S.upper_bound(currem);
      if (it == S.end()) {
        nxtrem = p + *S.begin();
      } else {
        nxtrem = *it;
      }
    }
    int nxtx = (nxtrem == -1 ? INF : curx / p * p + nxtrem);
    if (!era.empty() && era.back().first < nxtx) {
      int rem = era.back().second;
      cnt[rem]--;
      if (!cnt[rem]) {
        S.insert(rem);
      }
      curx = max(curx, era.back().first);
      era.pop_back();
      continue;
    }
    curx = nxtx;
    if (curx <= mx)
      res.push_back(curx);
    else
      break;
  }
  cout << (int)(res).size() << '\n';
  for (int x : res) cout << x << " ";
  cout << '\n';
}
