#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, m;
  cin >> n >> m;
  vector<long long> v(n);
  map<long long, long long> mp;
  queue<long long> q;
  for (int i = 0; i < n; i++) {
    cin >> v[i];
    mp[v[i]] = 0;
    q.push(v[i]);
  }
  vector<long long> res;
  long long ans = 0;
  while (!q.empty()) {
    long long cur = q.front();
    q.pop();
    if (res.size() == m) break;
    if (mp[cur] != 0) {
      res.push_back(cur);
      ans += mp[cur];
    }
    if (!mp.count(cur - 1)) {
      mp[cur - 1] = mp[cur] + 1;
      q.push(cur - 1);
    }
    if (!mp.count(cur + 1)) {
      mp[cur + 1] = mp[cur] + 1;
      q.push(cur + 1);
    }
  }
  cout << ans << "\n";
  for (int i = 0; i < res.size(); i++) cout << res[i] << " ";
  cout << "\n";
  return 0;
}
