#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
int main() {
  int n;
  cin >> n;
  int p;
  cin >> p;
  long long int pre[2002];
  for (int i = 0; i < 2002; i++) pre[i] = 0;
  int max_v = INT_MIN;
  for (int i = 0; i < n; i++) {
    int y;
    cin >> y;
    max_v = max(max_v, y);
    pre[y]++;
  }
  for (int i = 1; i < 2002; i++) pre[i] += pre[i - 1];
  vector<int> v;
  for (int x = 1; x < min(2000, max_v); x++) {
    long long int ans = pre[x];
    int curr = x;
    bool can = true;
    if (ans % p == 0) can = false;
    for (int j = 1; j < n; j++) {
      if (can == false) break;
      if (curr < 2000) curr++;
      int y = pre[curr];
      long long int z = y - (j);
      if (z % p == 0) {
        can = false;
        break;
      }
    }
    if (can == true) {
      if (ans % p != 0) v.push_back(x);
    }
  }
  cout << v.size() << endl;
  for (int i = 0; i < v.size(); i++) cout << v[i] << " ";
}
