#include <bits/stdc++.h>
using namespace std;
const int maxn = 200009;
const int MOD = 1e9 + 7;
int main() {
  ios_base::sync_with_stdio(false), cout.tie(0), cin.tie(0);
  int n, p;
  cin >> n >> p;
  int Max = 0;
  map<int, int> cnt;
  for (int i = 0; i < n; ++i) {
    int a;
    cin >> a;
    cnt[a]++;
    Max = max(Max, a);
  }
  int cur = n;
  vector<int> ans;
  map<int, int> save, add;
  multiset<int> Se;
  for (int i = Max, j = n; j >= 1; --j, ++i)
    Se.insert(j % p), save[i] = j, add[i] = 0;
  cur -= cnt[Max];
  for (int i = Max - 1; i > Max - n && i >= 1; --i) {
    Se.erase(Se.find(((save[i + n] - add[i + n]) % p + p) % p));
    add[i] = add[i + 1] - 1;
    save[i] = cur;
    Se.insert(((save[i] - add[i]) % p + p) % p);
    if (!Se.count((-add[i]) % p)) {
      ans.push_back(i);
    }
    if (cnt[i]) cur -= cnt[i];
  }
  cout << ((int)(ans).size()) << '\n';
  sort(ans.begin(), ans.end());
  for (int i : ans) cout << i << " ";
  return 0;
}
