#include <bits/stdc++.h>
using namespace std;
const int maxn = 2010;
long long a[maxn];
vector<long long> v;
long long n, p;
long long f(long long x) {
  long long ans = 1;
  long long r = n;
  for (long long i = n - 1; i >= 0; i--) {
    long long y = 0;
    if (a[i] - x > 0) y = a[i] - x;
    if ((r - y) % p == 0) return p;
    ans *= (r - y);
    ans %= p;
    r--;
  }
  return ans;
}
int main() {
  cin >> n >> p;
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a, a + n);
  long long ans = 0;
  long long minl = a[0];
  long long maxl = a[n - 1];
  long long m = 1;
  for (long long i = n - 2; i >= 0; i--) {
    if (a[i] == a[n - 1]) {
      m++;
    } else
      break;
  }
  long long u = max(maxl - n + m, minl);
  for (long long i = u; i < maxl; i++) {
    if (f(i) % p != 0) {
      v.push_back(i);
      ans++;
    }
  }
  cout << ans << endl;
  if (!ans) return 0;
  for (long long i = 0; i < v.size(); i++) {
    if (i) cout << " ";
    cout << v[i];
  }
  cout << endl;
  return 0;
}
