#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, p;
  long long int i;
  cin >> n >> p;
  long long int a[n];
  for (i = 0; i < n; i++) cin >> a[i];
  long long int ans = 0;
  vector<long long int> v;
  for (long long int x = 1; x <= 2000; x++) {
    long long int h[4400];
    for (i = 0; i <= n + 1; i++) h[i] = 0;
    bool ok = true;
    for (i = 0; i < n; i++) {
      long long int res = x - a[i];
      if (res >= 0) {
        h[0]++;
      } else {
        res = abs(res);
        if (res >= n) ok = false;
        h[res]++;
      }
    }
    for (i = 1; i < n; i++) h[i] += h[i - 1];
    for (i = 0; i < n; i++) {
      h[i] = h[i] - i;
      if (h[i] < 0 || h[i] % p == 0) ok = false;
    }
    if (ok) {
      v.push_back(x);
      ans++;
    }
  }
  cout << ans << endl;
  for (i = 0; i < v.size(); i++) cout << v[i] << " ";
  return 0;
}
