#include <bits/stdc++.h>
using namespace std;
int main() {
  int numTrees, ppl;
  cin >> numTrees >> ppl;
  map<long long int, bool> visited;
  queue<pair<long long int, long long int>> q;
  for (int i = 0; i < numTrees; i++) {
    long long int tmp;
    cin >> tmp;
    q.push({tmp, 0});
  }
  vector<long long int> yj;
  long long int totalDist = 0;
  while (yj.size() != ppl) {
    auto top = q.front();
    q.pop();
    if (!visited.count(top.first) && top.second != 0) {
      yj.push_back(top.first);
      totalDist += top.second;
    }
    visited[top.first] = true;
    if (!visited.count(top.first + 1)) q.push({top.first + 1, top.second + 1});
    if (!visited.count(top.first - 1)) q.push({top.first - 1, top.second + 1});
  }
  cout << totalDist << endl;
  for (int i = 0; i < ppl; i++) cout << yj[i] << " ";
  return 0;
}
