#include <bits/stdc++.h>
using namespace std;
long long n, m, ans;
string str;
map<long long, long long> d;
long long sum;
queue<long long> q;
vector<long long> v1;
void bfs() {
  while (!q.empty()) {
    if ((long long)v1.size() == m) break;
    long long t = q.front();
    q.pop();
    if (d[t] != 0) {
      sum += d[t];
      v1.push_back(t);
    }
    if (!d.count(t + 1)) {
      d[t + 1] = d[t] + 1;
      q.push(t + 1);
    }
    if (!d.count(t - 1)) {
      d[t - 1] = d[t] + 1;
      q.push(t - 1);
    }
  }
}
long long solve() {
  cin >> n >> m;
  for (long long i = 1; i <= n; ++i) {
    long long t;
    cin >> t;
    q.push(t);
    d[t] = 0;
  }
  bfs();
  cout << sum << "\n";
  sort((v1).begin(), (v1).end());
  for (long long i = 0; i <= (long long)v1.size() - 1; ++i)
    cout << v1[i] << " ";
  return 0;
}
signed main() {
  ios::sync_with_stdio(0);
  long long t = 1;
  while (t--) solve();
  return 0;
}
