#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e3 + 10;
int max(int a, int b) {
  if (a > b) {
    return a;
  }
  return b;
}
int a[maxn], bk[2 * maxn];
int main() {
  int n, p;
  int mx = 0;
  cin >> n >> p;
  vector<int> res;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    mx = max(a[i], mx);
  }
  for (int i = 0; i < n; i++) {
    bk[max(0, a[i] - mx + n)]++;
  }
  for (int i = 1; i < 2 * n; i++) {
    bk[i] += bk[i - 1];
  }
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j < n; j++) {
      if ((bk[i + j] - j) <= 0) break;
      if ((bk[i + j] - j) % p == 0) break;
      if (j == n - 1) res.push_back(i + (mx - n));
    }
  }
  printf("%d\n", res.size());
  for (int i : res) {
    printf("%d ", i);
  }
  printf("\n");
}
