#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n, p;
  cin >> n >> p;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  int ma = a[n - 1];
  int lef = max(1, ma - (n - 1));
  int rig = ma - 1;
  int from = -1;
  auto get = [&](int x) {
    int it = 0;
    int cnt = 0;
    for (int i = 0; i < n; ++i) {
      while (it < n && a[it] <= x + i) {
        ++it;
        ++cnt;
      }
      if (cnt == p) {
        return 2;
      }
      if (cnt == 0) {
        return 0;
      }
      --cnt;
    }
    return 1;
  };
  while (lef <= rig) {
    int mid = (lef + rig) >> 1;
    int sign = get(mid);
    if (sign == 0) {
      lef = mid + 1;
    } else {
      from = mid;
      rig = mid - 1;
    }
  }
  if (from == -1) {
    cout << "0\n";
    return;
  }
  int to = -1;
  lef = from, rig = ma - 1;
  while (lef <= rig) {
    int mid = (lef + rig) >> 1;
    int sign = get(mid);
    if (sign == 2) {
      rig = mid - 1;
    } else {
      to = mid;
      lef = mid + 1;
    }
  }
  if (to < from) {
    cout << "0\n";
    return;
  }
  cout << to - from + 1 << "\n";
  for (int i = from; i <= to; ++i) {
    cout << i << " ";
  }
  cout << "\n";
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
