#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
vector<long long> bfs(queue<long long> q, set<long long> vis, int m) {
  vector<long long> res;
  while (true) {
    int first = q.front();
    q.pop();
    if (vis.find(first - 1) == vis.end()) {
      vis.insert(first - 1);
      res.push_back(first - 1);
      q.push(first - 1);
      m--;
    }
    if (m == 0) break;
    if (vis.find(first + 1) == vis.end()) {
      vis.insert(first + 1);
      res.push_back(first + 1);
      q.push(first + 1);
      m--;
    }
    if (m == 0) break;
  }
  return res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m;
  cin >> n >> m;
  vector<int> arr(n);
  queue<long long> q;
  set<long long> vis;
  for (int i = 0; i < ((int)arr.size()); ++i) {
    cin >> arr[i];
    q.push(arr[i]);
    vis.insert(arr[i]);
  }
  sort(arr.begin(), arr.end());
  vector<long long> res = bfs(q, vis, m);
  int ind = 0;
  long long tot = 0;
  sort(res.begin(), res.end());
  for (int i = 0; i < ((int)res.size()); ++i) {
    while (res[i] > arr[ind] && ind != (int)arr.size() - 1) ind++;
    long long adding = 0;
    if (ind == 0)
      adding = abs(arr[ind] - res[i]);
    else
      adding = min(abs(arr[ind] - res[i]), abs(arr[ind - 1] - res[i]));
    tot += adding;
  }
  cout << tot << endl;
  for (int i = 0; i < ((int)res.size()); ++i) cout << res[i] << " ";
  return 0;
}
