#include <bits/stdc++.h>
using namespace std;
const long long mxn = 505;
void solve() {
  long long n, m;
  cin >> n >> m;
  vector<long long> a(n);
  for (long long& x : a) cin >> x;
  multiset<pair<long long, pair<long long, long long>>> f;
  reverse(a.begin(), a.end());
  a.push_back(-1e11);
  reverse(a.begin(), a.end());
  a.push_back(1e11);
  sort(a.begin(), a.end());
  for (long long i = 1; i <= n; i++) {
    pair<long long, pair<long long, long long>> ff =
        make_pair(1LL, make_pair((a[i] - a[i - 1]) / 2, i * -1));
    pair<long long, pair<long long, long long>> ss =
        make_pair(1LL, make_pair((a[i + 1] - a[i] - 1) / 2, i * 1));
    if (ff.second.first) f.insert(ff);
    if (ss.second.first) f.insert(ss);
  }
  long long ans = 0;
  vector<long long> vans;
  while (m--) {
    auto it = f.begin();
    pair<long long, pair<long long, long long>> ch = *it;
    f.erase(ch);
    ans += ch.first;
    vans.push_back(a[abs(ch.second.second)] +
                   ch.first * (ch.second.second / abs(ch.second.second)));
    --ch.second.first, ++ch.first;
    if (ch.second.first == 0) continue;
    f.insert(ch);
  }
  cout << ans;
  sort(vans.begin(), vans.end());
  cout << endl;
  for (long long x : vans) cout << x << " ";
}
signed main() {
  long long t = 1;
  while (t--) {
    solve();
    cout << endl;
  }
}
