#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7;
int a[N], b[N];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, p;
  cin >> n >> p;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    a[i] = n - a[i];
  }
  sort(a + 1, a + n + 1);
  vector<int> ans;
  for (int x = 1; x <= 4000; x++) {
    bool good = true;
    for (int i = 1; i <= n; i++) {
      int ww = min(a[i] + x, n) - (i - 1);
      if (ww % p == 0 || ww <= 0) good = false;
    }
    if (good) ans.push_back(x);
  }
  cout << ans.size() << endl;
  for (int x : ans) cout << x << " ";
}
