#include <bits/stdc++.h>
using namespace std;
const long long int MOD = 1e9 + 7;
const long long int NUM = 50;
void solve() {
  long long int n, m;
  cin >> n >> m;
  long long int ultcheck = 0;
  vector<long long int> vect(n);
  vector<long long int> people;
  long long int sum = 0;
  queue<long long int> q;
  map<long long int, long long int> d;
  for (long long int i = 0; i < n; i++) {
    cin >> vect[i];
    d[vect[i]] = 0;
    q.push(vect[i]);
  }
  while (!q.empty()) {
    if (people.size() == m) break;
    long long int cur = q.front();
    q.pop();
    if (d[cur]) {
      sum += abs(d[cur]);
      people.push_back(cur);
    }
    if (d.count(cur - 1) == 0) {
      d[cur - 1] = d[cur] + 1;
      q.push(cur - 1);
    }
    if (d.count(cur + 1) == 0) {
      d[cur + 1] = d[cur] + 1;
      q.push(cur + 1);
    }
  }
  cout << sum << endl;
  sort(people.begin(), people.end());
  for (long long int i = 0; i < people.size(); i++) cout << people[i] << " ";
}
int main() {
  long long int test = 1;
  while (test--) solve();
}
