#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 3e5 + 5;
ll n, p;
ll a[N];
ll m, b[N];
ll num[N];
multiset<int> ms;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> p;
  for (int i = 1; i <= n; i++) cin >> a[i];
  sort(a + 1, a + 1 + n);
  for (ll i = a[n] - n + 1; i <= a[n] + n - 2; i++) {
    b[++m] = i;
  }
  for (int i = 1; i <= n; i++) {
    int id = lower_bound(b + 1, b + 1 + m, a[i]) - b;
    if (id >= 1 && id <= m) {
      num[id]++;
    }
  }
  for (int i = 1; i <= m; i++) {
    num[i] = num[i - 1] + num[i];
  }
  for (int i = 1; i <= m; i++) {
    num[i] = (((num[i] - b[i]) % p) + p) % p;
  }
  for (int i = 1; i <= n; i++) ms.insert(num[i]);
  vector<ll> ans;
  for (int i = 1; i <= m; i++) {
    if (b[i] >= a[n]) break;
    int val = (p - (b[i] % p) + p) % p;
    if (ms.find(val) == ms.end()) {
      ans.push_back(b[i]);
    }
    auto it = ms.find(num[i]);
    ms.erase(it);
    ms.insert(num[i + n]);
  }
  cout << ans.size() << "\n";
  for (int i : ans) {
    cout << i << " ";
  }
}
