#include <bits/stdc++.h>
void merging(int arr[], int low, int mid, int high) {
  int l1, l2, i, b[200005];
  for (l1 = low, i = low, l2 = mid + 1; l1 <= mid && l2 <= high; i++) {
    if (arr[l1] <= arr[l2])
      b[i] = arr[l1++];
    else {
      b[i] = arr[l2++];
    }
  }
  while (l1 <= mid) {
    b[i++] = arr[l1++];
  }
  while (l2 <= high) {
    b[i++] = arr[l2++];
  }
  for (i = low; i <= high; i++) {
    arr[i] = b[i];
  }
}
void sort(int arr[], int low, int high) {
  int mid;
  if (low < high) {
    mid = (low + high) / 2;
    sort(arr, low, mid);
    sort(arr, mid + 1, high);
    merging(arr, low, mid, high);
  }
}
int main() {
  int p, n, a[100005], i, arr[100005], l = 0, r = -1, x, ans, temp, flag;
  scanf("%d %d", &n, &p);
  for (i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  sort(a, 0, n - 1);
  l = 0, r = -1;
  for (x = a[n - 1] - n + 1; x < a[n - 1]; x++) {
    ans = 1, flag = 0;
    ;
    for (i = n - 1; i >= 0; i--) {
      if (a[i] > x) {
        temp = i + 1 - (a[i] - x);
        if (temp % p == 0) {
          flag = 1;
        }
      } else {
        if (i + 1 >= p) {
          flag = 1;
        }
        break;
      }
    }
    if (flag == 0) {
      arr[++r] = x;
    }
  }
  if (r < l) {
    printf("0\n");
  } else {
    printf("%d\n", r - l + 1);
    for (i = l; i <= r; i++) {
      printf("%d ", arr[i]);
    }
    printf("\n");
  }
}
