#include <bits/stdc++.h>
using namespace std;
const long long N = 4060;
long long pfx[N];
void solve() {
  long long n, m;
  cin >> n >> m;
  long long a[n], mn = INT_MAX, mx = INT_MIN;
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
    mn = min(mn, a[i]);
    mx = max(mx, a[i]);
    pfx[a[i]]++;
  }
  for (long long i = 1; i < N; i++) pfx[i] += pfx[i - 1];
  long long cur, cond, ways;
  vector<long long> ans;
  for (long long i = mn; i <= mx; i++) {
    cur = i;
    cond = true;
    for (long long j = 0; j < n; j++) {
      ways = pfx[cur] - j;
      if (ways % m == 0) {
        cond = false;
        break;
      }
      cur++;
    }
    if (cond) ans.push_back(i);
  }
  cout << ans.size() << '\n';
  for (long long &x : ans) cout << x << " ";
  cout << '\n';
  return;
}
int32_t main() {
  clock_t st = clock();
  ios_base ::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
