#include <bits/stdc++.h>
using namespace std;
const auto start_time = std::chrono::high_resolution_clock::now();
void timecalculater() {}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void __print(int x) { cout << x; }
void __print(long x) { cout << x; }
void __print(long long x) { cout << x; }
void __print(unsigned x) { cout << x; }
void __print(unsigned long x) { cout << x; }
void __print(unsigned long long x) { cout << x; }
void __print(float x) { cout << x; }
void __print(double x) { cout << x; }
void __print(long double x) { cout << x; }
void __print(char x) { cout << '\'' << x << '\''; }
void __print(const char *x) { cout << '\"' << x << '\"'; }
void __print(const string &x) { cout << '\"' << x << '\"'; }
void __print(bool x) { cout << (x ? "true" : "false"); }
template <typename T, typename V>
void __print(const pair<T, V> &x) {
  cout << '{';
  __print(x.first);
  cout << ',';
  __print(x.second);
  cout << '}';
}
template <typename T>
void __print(const T &x) {
  int f = 0;
  cout << '{';
  for (auto &i : x) cout << (f++ ? "," : ""), __print(i);
  cout << "}";
}
void _print() { cout << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) {
  __print(t);
  if (sizeof...(v)) cout << ", ";
  _print(v...);
}
long long p = 1e9 + 7;
const int N = 2e5 + 5;
int main() {
  cin.sync_with_stdio(0);
  cin.tie(0);
  cin.exceptions(cin.failbit);
  ;
  int T = 1;
  while (T--) {
    int n, p;
    cin >> n >> p;
    int a[n];
    for (int i = 0; i < (n); ++i) cin >> a[i];
    vector<int> ans;
    sort(a, a + n);
    long long lo = 1, hi = 1e9;
    long long low = -1, high = -1;
    while (lo <= hi) {
      long long x = (lo + hi) / 2;
      vector<int> v;
      int f = 1;
      long long r = 0;
      for (int j = n - 1; j >= 0; j--) {
        long long pos = a[j] - x;
        pos = max(0 * 1LL, pos);
        long long num = n - pos - r;
        r++;
        if (num <= 0) {
          f = 0;
          break;
        }
      }
      if (f) {
        low = x;
        hi = x - 1;
      } else {
        lo = x + 1;
      }
    }
    if (low == -1) {
      cout << 0;
      return 0;
    }
    lo = low, hi = 1e9;
    while (lo <= hi) {
      long long x = (lo + hi) / 2;
      vector<int> v;
      int f = 1;
      long long r = 0;
      for (int j = n - 1; j >= 0; j--) {
        long long pos = a[j] - x;
        pos = max(0 * 1LL, pos);
        long long num = n - pos - r;
        r++;
        if (num % p == 0) {
          f = 0;
          break;
        }
        if (num <= 0) {
          f = 0;
          break;
        }
      }
      if (f) {
        high = x;
        lo = x + 1;
      } else {
        hi = x - 1;
      }
    }
    if (high == -1) {
      cout << 0;
      return 0;
    }
    cout << (high - low + 1) << '\n';
    for (int i = low; i <= high; i++) {
      cout << i << " ";
    }
  }
  timecalculater();
  return 0;
}
