#include <bits/stdc++.h>
using namespace std;
void print(queue<long long> q) {
  cout << "q: ";
  while (q.size()) {
    cout << q.front() << " ";
    q.pop();
  }
  cout << '\n';
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long n, m, temp, tot_dist = 0;
  cin >> n >> m;
  queue<long long> q;
  map<long long, bool> vis;
  for (long long i = 0; i < n; i++) cin >> temp, q.push(temp), vis[temp] = true;
  q.push(INT_MAX);
  vector<long long> ans;
  long long cur_dis = 1;
  while (ans.size() < m) {
    long long u = q.front();
    q.pop();
    if (u == INT_MAX) {
      q.push(INT_MAX);
      cur_dis++;
      continue;
    }
    if (vis.find(u + 1) == vis.end()) {
      vis[u + 1] = true;
      q.push(u + 1);
      ans.push_back(u + 1);
      tot_dist += cur_dis;
    }
    if (ans.size() < m && vis.find(u - 1) == vis.end()) {
      vis[u - 1] = true;
      q.push(u - 1);
      ans.push_back(u - 1);
      tot_dist += cur_dis;
    }
  }
  cout << tot_dist << '\n';
  for (long long x : ans) cout << x << " ";
  return 0;
}
