#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> x(n);
  for (int i = 0; i < n; ++i) {
    cin >> x[i];
  }
  queue<int> q;
  map<int, int> mp;
  for (int i = 0; i < n; ++i) {
    mp[x[i]] = 0;
    q.push(x[i]);
  }
  vector<int> ans;
  long long int sum = 0;
  while (!q.empty()) {
    if (ans.size() == m) break;
    int cur = q.front();
    q.pop();
    if (mp[cur] != 0) {
      sum += mp[cur];
      ans.push_back(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 << sum << endl;
  for (auto i : ans) cout << i << " ";
}
