#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, p;
  cin >> n >> p;
  vector<int> v(n);
  for (int c = 0; c < n; c++) cin >> v[c];
  sort(v.begin(), v.end());
  long long minimum = 0;
  long long won = 0;
  for (int c = 0; c < v.size(); c++) {
    if (minimum + won < v[c]) {
      minimum += v[c] - (won + minimum);
    }
    won++;
  }
  long long gauche = 0, droite = v.back();
  while (gauche != droite) {
    long long mid = (gauche + droite) / 2 + 1;
    long long current = mid;
    bool valid = true;
    int curseur = 0;
    int previousCurseur = -1;
    for (int c = 0; c < n; c++) {
      int c2;
      for (c2 = c; c2 + 1 < n && v[c2 + 1] <= c + current; c2++) {
      }
      if (c2 - c + 1 >= p) {
        valid = false;
        break;
      }
    }
    if (valid) {
      gauche = mid;
    } else {
      droite = mid - 1;
    }
  }
  cout << max(0LL, gauche - minimum + 1) << "\n";
  for (int c = minimum; c <= gauche; c++) cout << c << " ";
}
