#include <bits/stdc++.h>
using namespace std;
const long long nax = 1e5 + 5;
vector<long long> adj[nax];
map<long long, long long> visited;
long long td = 0;
vector<long long> v;
long long cnt;
signed main() {
  long long n, m;
  queue<pair<long long, long long>> q;
  cin >> n >> m;
  while (n--) {
    long long a;
    cin >> a;
    q.push({a, 0});
    visited[a] = 1;
  }
  while (!q.empty()) {
    long long cur_pt = q.front().first;
    long long dis = q.front().second;
    q.pop();
    if (v.size() <= m - 1) {
      if (dis != 0) {
        td += dis;
        v.push_back(cur_pt);
      }
    } else {
      break;
    }
    if (!visited.count(cur_pt - 1)) {
      visited[cur_pt - 1] = 1;
      q.push({cur_pt - 1, dis + 1});
    }
    if (!visited.count(cur_pt + 1)) {
      visited[cur_pt + 1] = 1;
      q.push({cur_pt + 1, dis + 1});
    }
  }
  cout << td << endl;
  for (auto u : v) {
    cout << u << " ";
  }
  cout << endl;
  return 0;
}
