#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  long long n, p;
  cin >> n >> p;
  vector<long long> a(n), ans;
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  for (long long x = 1; x <= 2000; x++) {
    long long f = 1;
    for (long long i = n - 1; i >= 0; i--) {
      long long u = n - (a[i] - x);
      if (x >= a[i]) {
        u = n;
      }
      if (u - (n - i - 1) < 0) {
        f = 0;
        break;
      }
      if ((u - (n - i - 1)) % p == 0) {
        f = 0;
        break;
      }
    }
    if (f) ans.push_back(x);
  }
  cout << ans.size() << '\n';
  for (long long to : ans) {
    cout << to << ' ';
  }
  return 0;
}
