#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pi = pair<int, int>;
using vi = vector<int>;
const int nax = 200 * 1000 + 10;
int n, p;
int a[nax];
int cnt[2 * nax];
multiset<int> rest;
vi ans;
void eval(int x) {
  for (int i = 0; i <= n; ++i) {
    cnt[i] = 0;
  }
  for (int i = 0; i < n; ++i) {
    cnt[max(0, a[i] - x)]++;
  }
  int sum = 0;
  for (int i = 0; i < n; ++i) {
    sum = sum + cnt[i];
    rest.insert((sum - i + p) % p);
  }
  int con = (sum - (n - 1) + p) % p;
  sum = 0;
  for (int i = 0; i < n; ++i) {
    sum = sum + cnt[i];
    int y = (p - (i % p)) % p;
    if (rest.find(y) == rest.end()) {
      ans.push_back(x + i);
    }
    int y2 = (sum - i + p) % p;
    rest.erase(rest.find(y2));
    rest.insert((con - (i + 1) + p) % p);
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> p;
  int mx = 0;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    mx = max(mx, a[i]);
  }
  int start = max(1, mx - n + 1);
  eval(start);
  cout << (int)ans.size() << "\n";
  for (auto it : ans) {
    cout << it << " ";
  }
}
