#include <bits/stdc++.h>
using namespace std;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int64_t n, m;
  cin >> n >> m;
  queue<pair<int64_t, int64_t> > q;
  map<int64_t, bool> used;
  for (int64_t i = 0; i < n; i++) {
    int64_t x;
    cin >> x;
    used[x] = true;
    q.push({x - 1, 1});
    q.push({x + 1, 1});
  }
  vector<int64_t> res;
  int64_t sum = 0;
  while (m > 0) {
    pair<int64_t, int64_t> c = q.front();
    q.pop();
    if (used[c.first]) continue;
    used[c.first] = true;
    sum += c.second;
    res.push_back(c.first);
    m--;
    if (!used[c.first - 1]) q.push({c.first - 1, c.second + 1});
    if (!used[c.first + 1]) q.push({c.first + 1, c.second + 1});
  }
  cout << sum << endl;
  for (int64_t i = 0; i < res.size(); i++) cout << res[i] << " ";
}
