#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const long long inf = 1e15;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout << fixed << setprecision(9);
  long long n, m;
  cin >> n >> m;
  vector<long long> a(n);
  for (long long i = 0; i < n; ++i) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  queue<pair<long long, long long> > q;
  set<long long> vis;
  for (long long i = 0; i < n; ++i) {
    q.push({a[i], i});
    vis.insert(a[i]);
  }
  vector<long long> ans;
  long long res = 0;
  while (m > 0) {
    pair<long long, long long> cur = q.front();
    q.pop();
    long long pos = cur.first;
    long long ind = cur.second;
    if (m <= 0) break;
    long long npos = pos + 1;
    if (!vis.count(npos)) {
      --m;
      ans.push_back(npos);
      res += abs(npos - a[ind]);
      q.push({npos, ind});
      vis.insert(npos);
    }
    if (m <= 0) break;
    npos = pos - 1;
    if (!vis.count(npos)) {
      --m;
      ans.push_back(npos);
      res += abs(npos - a[ind]);
      q.push({npos, ind});
      vis.insert(npos);
    }
  }
  sort(ans.begin(), ans.end());
  cout << res << '\n';
  for (long long i = 0; i < (long long)ans.size(); ++i) {
    cout << ans[i] << " ";
  }
  cout << '\n';
  return 0;
}
