#include <bits/stdc++.h>
using namespace std;
using ld = long double;
template <class T>
inline T gcd(T a, T b) {
  return !a ? b : gcd(b % a, a);
}
template <class T>
inline T lcm(T a, T b) {
  return (a * b) / gcd(a, b);
}
mt19937 rnd(time(0));
void solve() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  queue<int> q;
  map<int, int> d;
  for (int i = 0; i < n; i++) {
    d[a[i]] = 0;
    q.push(a[i]);
  }
  long long ans = 0ll;
  vector<int> points;
  while (!q.empty()) {
    if ((int)points.size() == m) {
      break;
    }
    int v = q.front();
    q.pop();
    if (d[v] != 0) {
      ans += d[v];
      points.push_back(v);
    }
    if (!d.count(v + 1)) {
      d[v + 1] = d[v] + 1;
      q.push(v + 1);
    }
    if (!d.count(v - 1)) {
      d[v - 1] = d[v] + 1;
      q.push(v - 1);
    }
  }
  cout << ans << '\n';
  for (int x : points) {
    cout << x << " ";
  }
  return;
}
signed main() {
  ios_base ::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  int t = 1;
  while (t-- > 0) {
    solve();
  }
  return 0;
}
