#include <bits/stdc++.h>
using namespace std;
long long n, p;
bool check(vector<long long> a, long long candies) {
  bool flag = 1;
  for (long long i = 0; i < n; i++) {
    long long y = upper_bound(a.begin(), a.end(), candies) - a.begin();
    long long x = y - i;
    if (x % p == 0) {
      flag = 0;
      break;
    }
    candies++;
  }
  return flag;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(0);
  ;
  long long test = 1;
  while (test--) {
    cin >> n >> p;
    long long mx = 0, mn = 10000000;
    vector<long long> a;
    for (long long i = 0; i < n; i++) {
      long long x;
      cin >> x;
      a.push_back(x);
    }
    sort(a.begin(), a.end());
    mx = a[n - 1];
    mn = a[0];
    long long start = max(mx - n + 1, mn);
    for (long long i = 0; i < n; i++) {
      start = max(start, a[i] - i);
    }
    vector<long long> possible;
    for (long long i = start; i < mx; i++) possible.push_back(i);
    if (possible.size() == 0) return cout << "  0", 0;
    long long low = 0, high = possible.size() - 1, mid, ind = possible.size();
    while (low <= high) {
      mid = low + (high - low) / 2;
      if (check(a, possible[mid]))
        low = mid + 1;
      else {
        ind = mid;
        high = mid - 1;
      }
    }
    cout << ind << '\n';
    for (long long i = 0; i < ind; i++) cout << possible[i] << ' ';
  }
}
