#include <bits/stdc++.h>
using namespace std;
template <typename _A, typename _B>
using _p = pair<_A, _B>;
template <typename _A>
using _v = vector<_A>;
template <typename _A>
using _q = queue<_A>;
template <typename _A>
using _s = set<_A>;
template <typename _A>
using _st = stack<_A>;
template <typename _A>
using _d = deque<_A>;
template <typename _A>
using _pq = priority_queue<_A>;
template <typename _A, typename _C>
using _pqc = priority_queue<_A, _v<_A>, _C>;
const int NM = 3e5 + 5;
int N, P, A[NM];
int b[NM];
int main(void) {
  scanf("%d%d", &N, &P);
  int st, fi;
  int bmx = 0, rc = 0;
  for (int i = 0; i < N; i++) scanf("%d", &A[i]), bmx = max(bmx, A[i]);
  for (int i = 0; i < N; i++) b[max(0, A[i] - bmx + N)]++;
  for (int i = 1; i < NM; i++) b[i] += b[i - 1];
  _v<int> ans;
  for (int i = 0, j; i <= N; i++) {
    for (j = 0; j < N; j++) {
      if (b[i + j] - j <= 0) break;
      if (!((b[i + j] - j) % P)) break;
      if (j == N - 1) ans.push_back(i + bmx - N);
    }
  }
  printf("%zu\n", ans.size());
  for (auto &it : ans) printf("%d ", it);
  return 0;
}
