#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, p;
  vector<long long int> v;
  cin >> n;
  cin >> p;
  for (long long int i = 0; i < n; i++) {
    long long int x;
    cin >> x;
    v.push_back(x);
  }
  sort(v.begin(), v.end());
  vector<long long int> v2;
  for (long long int i = 0; i < n; i++) {
    v2.push_back(v[i] - i);
  }
  long long int max = v2[0];
  long long int maxi = 0;
  for (long long int i = 1; i < n; i++) {
    if (v2[i] > max) {
      max = v2[i];
      maxi = i;
    }
  }
  for (long long int i = 0; i < n; i++) {
    if (v2[i] - 1 > 0) {
      v2[i] = (v2[i] - 1) % p;
    } else {
      long long int g = -1 * (v2[i] - 1);
      g = g % p;
      v2[i] = p - g;
    }
  }
  map<long long int, long long int> m, m2;
  for (long long int i = 0; i < p; i++) {
    m2[i] = 0;
  }
  for (long long int i = 0; i < n; i++) {
    m[v2[i]] = v[i];
    m2[v2[i]] = 1;
  }
  vector<long long int> v3;
  long long int count = 0;
  for (long long int i = max; i < v[p - 1]; i++) {
    long long int x = (i % p);
    if (m2[x] == 0) {
      count++;
      v3.push_back(i);
    } else {
      if (m[x] < i) {
        count++;
        v3.push_back(i);
      }
    }
  }
  cout << count << "\n";
  for (long long int i = 0; i < v3.size(); i++) {
    cout << v3[i] << " ";
  }
  return 0;
}
