#include <bits/stdc++.h>
using namespace std;
const long long INF = 2000000000000000000LL;
const int inf = 0x3f3f3f3f;
const long double EPS = 1e-9;
int arr[200009];
int bfs() {
  int n, m;
  long long cost = 0;
  cin >> n >> m;
  map<int, int> taken;
  map<pair<int, int>, int> qtaken;
  queue<pair<int, int> > process;
  int value;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    taken[arr[i]] = 0;
  }
  for (int i = 0; i < n; i++) {
    value = arr[i];
    int left = value - 1, right = value + 1;
    if (taken.find(left) == taken.end() && m) {
      taken[left] = 1;
      m--;
      cost++;
      if (qtaken.find({1, value}) == qtaken.end())
        process.push({1, value}), qtaken[{1, value}] = 1;
    }
    if (taken.find(right) == taken.end() && m) {
      taken[right] = 1;
      m--;
      cost++;
      if (qtaken.find({1, value}) == qtaken.end())
        process.push({1, value}), qtaken[{1, value}] = 1;
    }
    if (!m) break;
  }
  pair<int, int> top, now;
  int cst = 0, left, right;
  while (!process.empty() && m) {
    top = process.front();
    process.pop();
    cst = top.first + 1, left = top.second - cst, right = top.second + cst;
    if (taken.find(left) == taken.end() && m) {
      taken[left] = 1;
      m--;
      cost += cst;
      if (qtaken.find({cst, top.second}) == qtaken.end())
        process.push({cst, top.second}), qtaken[{cst, top.second}] = 1;
    }
    if (taken.find(right) == taken.end() && m) {
      taken[right] = 1;
      m--;
      cost += cst;
      if (qtaken.find({cst, top.second}) == qtaken.end())
        process.push({cst, top.second}), qtaken[{cst, top.second}] = 1;
    }
    if (!m) break;
  }
  cout << cost << endl;
  for (auto it : taken)
    if (it.second) cout << it.first << " ";
  return cost;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  int cost = bfs();
  return 0;
}
