#include <bits/stdc++.h>
using namespace std;
using LL = long long;
const int maxn = 2005;
int a[maxn];
int main() {
  int n, p;
  scanf("%d%d", &n, &p);
  int i;
  for (i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  sort(a, a + n, greater<int>());
  vector<int> ans;
  int x;
  for (x = 1; x < 2000; x++) {
    int num = 0;
    int res = 0;
    for (i = 0; i < n; i++) {
      if (a[i] <= x) {
        num++;
      } else {
        int now = a[i] - x;
        int d = n - now - res;
        if (d <= 0) {
          break;
        } else {
          if (d % p == 0)
            break;
          else {
            res++;
          }
        }
      }
    }
    if (num < p && i == n) {
      ans.push_back(x);
    }
  }
  printf("%d\n", (int)ans.size());
  for (i = 0; i + 1 < ans.size(); i++) {
    printf("%d ", ans[i]);
  }
  if (ans.size())
    printf("%d\n", ans[i]);
  else
    printf("\n");
  return 0;
}
