#include <bits/stdc++.h>
bool f(int x, int n, int *pre, int p) {
  for (int j = 0; j < n; ++j) {
    if ((pre[j + x] - j) % p == 0) return false;
  }
  return true;
}
using namespace std;
int main(int argc, char **argv) {
  vector<int> ans;
  int t, n, p, a[2000], pre[5001] = {0};
  cin >> n >> p;
  for (int i = 0; i < n; ++i) cin >> a[i];
  sort(a, a + n);
  int mn = a[0], mx = a[n - 1];
  t = 0;
  for (int i = 1; i <= 5000; ++i) {
    pre[i] = pre[i - 1];
    while (t < n && a[t] <= i) ++t, ++pre[i];
  }
  for (int i = mn; i <= 2000; ++i) {
    if (f(i, n, pre, p)) ans.push_back(i);
  }
  cout << ans.size() << endl;
  for (int i = 0; i < ans.size(); ++i) {
    cout << ans[i] << (i == ans.size() - 1 ? '\n' : ' ');
  }
  return 0;
}
