#include <bits/stdc++.h>
using namespace std;
const int64_t INF = (int64_t)(2e18);
const int inf = (int)(1e9 + 7);
const int maxn = 500 * 1000 + 100;
int n, p;
vector<int> vec;
bool solve(int x) {
  auto v = vec;
  for (auto& it : v) it -= x;
  for (auto& it : v) it = max(it, 0);
  for (auto& it : v) it = n - it;
  sort((v).begin(), (v).end());
  for (int i = 0; i < n; ++i) {
    auto& it = v[i];
    if (it - i <= 0) return false;
    if ((it - i) % p == 0) return false;
  }
  return true;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  cin.tie(nullptr);
  cin >> n >> p;
  vec.resize(n);
  vector<int> res;
  for (auto& it : vec) cin >> it;
  for (int i = 0; i < 2400; ++i) {
    if (solve(i)) res.push_back(i);
  }
  cout << res.size() << endl;
  for (auto& it : res) cout << it << " ";
  return 0;
}
