#include <bits/stdc++.h>
constexpr int MAX_N = 2000;
constexpr int MAX_A = 2000;
int A[MAX_N + 10];
int B[MAX_N + 10];
int Ans[MAX_N + 10];
void solve(void) {
  int n, p;
  std::cin >> n >> p;
  for (int i = 0; i < n; ++i) std::cin >> A[i];
  std::sort(A, A + n);
  int len = 0;
  for (int x = 1; x <= MAX_A; ++x) {
    for (int i = 0; i < n; ++i) {
      B[i] = A[i] - x;
      if (B[i] < 0) B[i] = 0;
    }
    bool flag = true;
    for (int i = 0, r = 0; i < n; ++i) {
      while (r < n and B[r] <= i) ++r;
      if (r < i or (r - i) % p == 0) {
        flag = false;
        break;
      }
    }
    if (flag) {
      Ans[len++] = x;
    }
  }
  std::cout << len << '\n';
  if (len) std::cout << Ans[0];
  for (int i = 1; i < len; ++i) std::cout << ' ' << Ans[i];
  std::cout << '\n';
}
int main(void) {
  std::cin.tie(nullptr);
  std::cin.sync_with_stdio(false);
  solve();
  return 0;
}
