#include <bits/stdc++.h>
const long long int inf = 9e18;
const long double pi = 2 * acos(0.0);
using namespace std;
long long int power(long long int a, long long int n) {
  if (n == 0) {
    return 1;
  }
  long long int p = power(a, n / 2) % 998244353;
  p = (p * p) % 998244353;
  if (n % 2 == 1) {
    p = (p * a) % 998244353;
  }
  return p;
}
long long int gcd(long long int a, long long int b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
int isprime(long long int n) {
  for (long long int i = 2; i <= sqrt(n); i++) {
    if (n % i == 0) {
      return 0;
    }
  }
  return 1;
}
const int N = 1e6;
vector<long long int> sieve(N, 0);
void si() {
  sieve[1] = 1;
  for (int i = 2; i < N; i++) {
    if (sieve[i] == 0) {
      for (int j = i; j < N; j += i) {
        sieve[j] = i;
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  long long int n, p;
  cin >> n >> p;
  vector<long long int> a(n);
  ;
  for (long long int i = 0; i < n; i++) cin >> a[i];
  ;
  sort(a.begin(), a.end());
  vector<long long int> ans;
  for (int i = 1; i <= 2000; i++) {
    vector<long long int> b(n, 0);
    for (int j = 0; j < n; j++) {
      if (i >= a[j]) {
        b[j] = n;
      } else {
        b[j] = n - (a[j] - i);
      }
    }
    int c = 0;
    for (int j = n - 1; j >= 0; j--) {
      b[j] -= c;
      c++;
    }
    long long int flag = 0;
    for (int j = n - 1; j >= 0; j--) {
      if (b[j] <= 0) {
        flag = -1;
        break;
      } else if (b[j] % p == 0) {
        flag = -1;
        break;
      }
    }
    if (flag == 0) {
      ans.push_back(i);
    }
  }
  cout << (int)(ans.size()) << "\n";
  for (int i = 0; i < (int)(ans.size()); i++) {
    cout << ans[i] << " ";
  }
  cout << "\n";
  return 0;
}
