#include <bits/stdc++.h>
using namespace std;
const int N = 1.1e5;
int a[N];
int main() {
  srand(time(0));
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, p;
  cin >> n >> p;
  map<int, int> freq;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    ++freq[a[i]];
  }
  vector<int> b(2 * n + 10);
  int mx = *max_element(a, a + n);
  int low = max(1, mx - n + 1);
  int less = 0;
  for (int i = 0; i < n; ++i) {
    if (a[i] <= low - 1) {
      ++less;
    }
  }
  for (int i = low; i <= mx + n; ++i) {
    less += freq[i];
    int md = (i - less) % p;
    if (md < 0) md += p;
    b[i - low] = md;
  }
  freq.clear();
  vector<int> ans;
  for (int i = 0; i < n; ++i) ++freq[b[i]];
  if (freq[low % p] == 0) ans.push_back(low);
  for (int i = 1; i <= mx - low - 1; ++i) {
    --freq[b[i - 1]];
    ++freq[b[i + n - 1]];
    int v = i + low;
    if (freq[v % p] == 0) {
      ans.push_back(v);
    }
  }
  cout << ans.size() << '\n';
  for (int x : ans) cout << x << ' ';
  cout << '\n';
  return 0;
}
