#include <bits/stdc++.h>
using namespace std;
vector<long long> arr(2001);
long long n, p;
long long bin(long long start, long long end) {
  long long ans = end;
  while (start < end) {
    long long mid = (start + end + 1) / 2;
    long long w = mid;
    long long rr = 0;
    for (long long i = (0); i < (n); i++) {
      if (w < arr[i]) {
        rr = 1;
        break;
      }
      w++;
    }
    if (rr) {
      start = mid + 1;
    } else {
      ans = mid;
      end = mid - 1;
    }
  }
  long long w = start;
  long long rr = 0;
  for (long long i = (0); i < (n); i++) {
    if (w < arr[i]) {
      rr = 1;
      break;
    }
    w++;
  }
  if (rr) {
    start++;
  }
  return start;
}
long long solve() {
  cin >> n >> p;
  arr.resize(n);
  for (long long i = (0); i < (n); i++) cin >> arr[i];
  sort((arr).begin(), (arr).end());
  long long start = ((1) > (arr[n - 1] - n + 1) ? (1) : (arr[n - 1] - n + 1));
  long long end = arr[p - 1] - 1;
  start = bin(start, end);
  if (start > end)
    cout << "0";
  else {
    long long ans = 0;
    vector<long long> answer;
    for (long long i = start; i <= end; i++) {
      long long y = 0;
      long long check = 0;
      for (long long j = n - 1; j >= 0; j--) {
        long long temp = ((0) > (arr[j] - i) ? (0) : (arr[j] - i));
        temp = n - temp - y;
        y++;
        if (temp % p == 0) {
          check = 1;
          break;
        }
      }
      if (!check) {
        answer.push_back(i);
        ans++;
      }
    }
    cout << ans << '\n';
    for (long long i = (0); i < ((long long)(answer).size()); i++) {
      cout << answer[i] << " ";
    }
  }
  return 0;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  while (t) {
    solve();
    t--;
  }
  cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << '\n';
  return 0;
}
