#include <bits/stdc++.h>
#pragma optimize("O3")
#pragma GCC target("sse4")
using namespace std;
template <int D, typename T>
struct Vec : public vector<Vec<D - 1, T>> {
  static_assert(D >= 1, "Vector dimension must be greater than zero!");
  template <typename... Args>
  Vec(int n = 0, Args... args)
      : vector<Vec<D - 1, T>>(n, Vec<D - 1, T>(args...)) {}
};
template <typename T>
struct Vec<1, T> : public vector<T> {
  Vec(int n = 0, const T& val = T()) : vector<T>(n, val) {}
};
long long int modpower(long long int x, long long int y, long long int p) {
  long long int res = 1;
  x = x % p;
  if (y == 0) return 1;
  if (x == 0) return 0;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
long long int power(long long int x, long long int y) {
  long long int res = 1;
  x = x;
  if (y == 0) return 1;
  if (x == 0) return 0;
  while (y > 0) {
    if (y & 1) res = (res * x);
    y = y >> 1;
    x = (x * x);
  }
  return res;
}
long long int modinv(long long int a, long long int p) {
  return modpower(a, p - 2, p);
}
const int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1},
          dy[8] = {0, 1, 0, -1, -1, 1, -1, 1};
long long safe_sqrt(long long n) {
  long long res = sqrt((long double)n);
  if (res * res == n) return res;
  const long double eps = 1e-8;
  if ((long double)(res + 1) * (res + 1) < n + eps) return res + 1;
  if ((long double)res * res + eps > n) return res - 1;
  return res;
}
void solve() {
  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());
  ;
  long long int ans = 0;
  long long int mx = *max_element(a.begin(), a.end());
  vector<long long int> res;
  for (long long int i = 1; i <= 2000; i += 1) {
    long long int x = i;
    long long int cur = 0;
    bool bad = false;
    long long int index = 0;
    while (cur < n) {
      if (index != n)
        while (a[index] <= x) {
          index++;
          if (index == n) {
            break;
          }
        }
      if ((index - cur) % p == 0) {
        bad = true;
        break;
      }
      cur++;
      x++;
    }
    if (bad == false) {
      ans++;
      res.push_back(i);
    }
  }
  cout << ans << '\n';
  for (auto v : res) {
    cout << v << " ";
  }
  cout << '\n';
  return;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int T = 1;
  for (long long int c = 0; c < T; c++) {
    solve();
  }
  return 0;
}
