#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  long* arr = new long[n];
  queue<long> q;
  map<long, long> d;
  for (long i = 0; i < n; i++) {
    cin >> arr[i];
    q.push(arr[i]);
    d[arr[i]] = 0;
  }
  long long ans = 0;
  vector<long> res;
  while (!q.empty()) {
    if (res.size() == m) break;
    long cur = q.front();
    q.pop();
    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 << "\n";
  for (auto ele : res) cout << ele << " ";
  cout << "\n";
}
