#include <bits/stdc++.h>
using namespace std;
int main() {
  long long t, n, m, i, ans = 0, cur;
  cin >> n >> m;
  long long a[n];
  queue<long long> q;
  map<long long, long long> d;
  vector<long long> res;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    d[a[i]] = 0;
    q.push(a[i]);
  }
  while (!q.empty()) {
    cur = q.front();
    q.pop();
    if (res.size() == m) break;
    if (d[cur] != 0) {
      ans += d[cur];
      res.push_back(cur);
    }
    if (!d.count(cur - 1)) {
      d[cur - 1] = d[cur] + 1;
      q.push(cur - 1);
    }
    if (!d.count(cur + 1)) {
      d[cur + 1] = d[cur] + 1;
      q.push(cur + 1);
    }
  }
  cout << ans << endl;
  for (i = 0; i < res.size(); i++) cout << res[i] << " ";
  return 0;
}
