#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
map<int, bool> is;
int x[200010];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m;
  queue<pair<int, long long>> q;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> x[i];
    is[x[i]] = true;
    q.push(make_pair(x[i] - 1, 1LL));
    q.push(make_pair(x[i] + 1, 1LL));
  }
  long long res = 0;
  vector<int> sol;
  while (!q.empty()) {
    int u = q.front().first;
    long long lvl = q.front().second;
    q.pop();
    if (!is[u]) {
      res += lvl;
      is[u] = true;
      sol.push_back(u);
      if (sol.size() == m) break;
    }
    if (!is[u - 1]) q.push(make_pair(u - 1, lvl + 1));
    if (!is[u + 1]) q.push(make_pair(u + 1, lvl + 1));
  }
  cout << res << endl;
  for (int i = 0; i < m; i++) cout << sol[i] << " ";
  cout << endl;
  return 0;
}
