#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long n, p;
  cin >> n >> p;
  vector<long long> a(n);
  for (long long i = 0; i < n; i++) cin >> a[i];
  sort(a.begin(), a.end());
  vector<long long> aa(5000, 0);
  for (long long i = 0; i < n; i++) aa[a[i]]++;
  for (long long i = 1; i < 5000; i++) aa[i] += aa[i - 1];
  set<long long> ans;
  for (long long x = *a.begin(); x < *a.rbegin(); x++) {
    long long s = x;
    bool k = true;
    for (long long i = 0; i < n; i++, s++) {
      if ((aa[s] - i) % p == 0) k = false;
    }
    if (k) ans.insert(x);
  }
  cout << ans.size() << endl;
  for (auto el : ans) cout << el << " ";
  cout << endl;
  return 0;
}
