#include <bits/stdc++.h>
using namespace std;
long long MOD = 1000000007;
long long binary_exp(long long a, long long b) {
  long long ans = 1;
  while (b > 0) {
    if (b & 1) {
      ans = (ans * a);
    }
    a = (a * a);
    b = b >> 1;
  }
  return ans;
}
int fn(int low, vector<int> &a, int p) {
  int k = low;
  for (int i = 0; i < a.size(); i++) {
    k = low + i;
    int j = upper_bound(a.begin(), a.end(), k) - a.begin();
    if ((j - i) % p == 0) {
      return 0;
    }
  }
  return 1;
}
map<long long, long long> mp;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long T;
  T = 1;
  while (T--) {
    int n, p;
    cin >> n >> p;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    sort(a.begin(), a.end());
    int low = max(a[0], a[n - 1] - n + 1);
    for (int i = 0; i < n; i++) {
      low = max(low, a[i] - i);
    }
    int high = a[n - 1];
    if (!fn(low, a, p)) {
      cout << 0 << endl;
      cout << endl;
      continue;
    }
    int z = low;
    while (low < high) {
      int mid = (low + high) / 2;
      mid++;
      if (fn(mid, a, p)) {
        low = mid;
      } else {
        high = mid - 1;
      }
    }
    cout << low - z + 1 << endl;
    for (int i = z; i <= low; i++) {
      cout << i << " ";
    }
    cout << endl;
  }
  return 0;
}
