#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
int n, p, a[N], b[N];
vector<int> res;
int main() {
  scanf("%d%d", &n, &p);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  sort(a + 1, a + n + 1);
  for (int i = 1; i <= n; i++) {
    int t = (a[i] + n - i) % p;
    b[t] = max(b[t], i);
  }
  for (int x = max(1, a[n] - n + 1); x <= a[n]; x++) {
    int pos = upper_bound(a + 1, a + n + 1, x) - a - 1;
    if (pos >= p || b[(x + n) % p] > pos) continue;
    res.push_back(x);
  }
  printf("%d\n", res.size());
  for (int i = 0; i < res.size(); i++) {
    printf("%d", res[i]);
    printf(i == res.size() - 1 ? "\n" : " ");
  }
  if (0 == res.size()) printf("\n");
  return 0;
}
