#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int n, m, x[N];
queue<long long> q;
vector<long long> res;
long long d[N], ans = 0;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> x[i];
  }
  map<long long, long long> d;
  for (int i = 1; i <= n; i++) {
    d[x[i]] = 0;
    q.push(x[i]);
  }
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    if (res.size() == m) break;
    if (d[u] != 0) {
      ans += d[u];
      res.push_back(u);
    }
    if (!d.count(u - 1)) {
      d[u - 1] = d[u] + 1;
      q.push(u - 1);
    }
    if (!d.count(u + 1)) {
      d[u + 1] = d[u] + 1;
      q.push(u + 1);
    }
  }
  cout << ans << '\n';
  for (auto v : res) {
    cout << v << " ";
  }
}
