#include <bits/stdc++.h>
using ll = long long;
using ld = long double;
using namespace std;
const ll inf = 2e18;
const ll mod = 1e9 + 7;
const ll N = 2e5 + 5;
void code() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n);
  for (auto &i : a) cin >> i;
  queue<pair<int, int>> q;
  set<int> occupied;
  for (auto i : a) q.emplace(i, 0), occupied.insert(i);
  long long dist = 0;
  int cnt = 0;
  vector<int> ans;
  while (!q.empty() and cnt < m) {
    auto [pos, d] = q.front();
    q.pop();
    int left = pos - 1;
    if (!occupied.count(left)) {
      q.emplace(left, d + 1);
      occupied.insert(left);
      cnt++;
      dist += d + 1;
      ans.push_back(left);
    }
    if (cnt >= m) break;
    int right = pos + 1;
    if (!occupied.count(right)) {
      q.emplace(right, d + 1);
      occupied.insert(right);
      cnt++;
      dist += d + 1;
      ans.push_back(right);
    }
  }
  cout << dist << "\n";
  sort((ans).begin(), (ans).end());
  for (auto i : ans) cout << i << " ";
  cout << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int t = 1;
  while (t-- > 0) {
    code();
  }
}
