#include <bits/stdc++.h>
using namespace std;
const int M = 998244353;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  int t = 1;
  while (t--) {
    int n, p;
    cin >> n >> p;
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    sort(a.begin(), a.end());
    vector<int> sol;
    for (int x = 1; x <= 2000; x++) {
      int cnt = 0;
      for (int i = 0; i < n; i++) {
        while (cnt < n && (a[cnt] <= x + i)) cnt++;
        int cur = cnt - i;
        if (cur < 0 || cur % p == 0) break;
        if (i == n - 1) sol.push_back(x);
      }
    }
    cout << sol.size() << "\n";
    for (int i = 0; i < (int)sol.size(); i++) {
      cout << sol[i] << " ";
    }
    if (sol.size()) cout << "\n";
  }
}
