#include <bits/stdc++.h>
using namespace std;
int main() {
  map<long long, long long> m;
  long long n, k;
  cin >> n >> k;
  queue<long long> q;
  long long x;
  for (long long i = 1; i <= n; i++) {
    cin >> x;
    m[x]++;
    q.push(x);
  }
  long long dist = 0;
  long long curr;
  vector<long long> a;
  long long ans = 0;
  long long done = 0;
  while (!q.empty()) {
    long long x = q.size();
    dist = dist + 1;
    while (x-- > 0) {
      curr = q.front();
      q.pop();
      if (m.find(curr - 1) == m.end()) {
        done++;
        ans += dist;
        a.push_back(curr - 1);
        m[curr - 1]++;
        q.push(curr - 1);
      }
      if (done == k) break;
      if (m.find(curr + 1) == m.end()) {
        done++;
        ans += dist;
        a.push_back(curr + 1);
        m[curr + 1]++;
        q.push(curr + 1);
      }
      if (done == k) break;
    }
    if (done == k) break;
  }
  cout << ans << "\n";
  for (long long i = 0; i < a.size(); i++) {
    cout << a[i] << " ";
  }
  return 0;
}
