#include <bits/stdc++.h>
using namespace std;
using ii = pair<int, int>;
using item = pair<int, ii>;
int main() {
  cin.sync_with_stdio(0);
  cin.tie(0);
  int i, n, m;
  cin >> n >> m;
  vector<int> x(n);
  vector<int> rest;
  queue<item> dist;
  for (i = 0; i < n; i++) cin >> x[i];
  sort(x.begin(), x.end());
  dist.push({1, {INT_MIN, 0}});
  dist.push({1, {INT_MAX, n - 1}});
  for (i = 0; i < n - 1; i++) {
    if (x[i + 1] - x[i] >= 2) dist.push({1, {i, i + 1}});
  }
  i = 0;
  int a, b, valor;
  long long sum = 0;
  auto ini = dist.front();
  while (i != m) {
    ini = dist.front();
    a = (ini.second).first;
    b = (ini.second).second;
    valor = ini.first;
    sum += valor;
    if (a == INT_MAX)
      rest.push_back(x[b] + valor);
    else
      rest.push_back(x[b] - valor);
    i++;
    dist.pop();
    if (i != m) {
      if (a != INT_MIN && a != INT_MAX) {
        if (x[b] - x[a] > 2 * valor) {
          i++;
          sum += valor;
          rest.push_back(x[a] + valor);
          if (x[b] - x[a] > 2 * valor + 1) dist.push({valor + 1, {a, b}});
        }
      } else {
        dist.push({valor + 1, {a, b}});
      }
    }
  }
  cout << sum << endl;
  for (i = 0; i < rest.size(); i++) cout << rest[i] << ' ';
  cout << endl;
  return 0;
}
