#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e9;
const long long inf64 = 1e18;
const long long MOD = inf + 7;
const long long N = 2005;
long long val[3 * N], pre[3 * N];
void solve() {
  long long n, p;
  cin >> n >> p;
  for (long long i = 0, x; i < n; i++) cin >> x, pre[x]++;
  for (long long i = 1; i < 3 * N; i++) pre[i] += pre[i - 1];
  vector<long long> ans;
  for (long long i = 1; i < N; i++) {
    long long sum = 1;
    long long crt = i;
    long long chk = 1;
    for (long long j = 0; j < n; j++) {
      long long temp = pre[crt] - j;
      if (temp % p == 0 && temp >= 0) {
        chk = 0;
      }
      crt++;
    }
    if (chk) ans.push_back(i);
  }
  cout << (long long)(ans).size() << "\n";
  for (auto X : ans) cout << X << " ";
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  while (t--) solve();
}
