#include <bits/stdc++.h>
using namespace std;
long long rr[] = {0, 1, 1, 1, 0, -1, -1, -1};
long long cc[] = {1, 1, 0, -1, -1, -1, 0, 1};
const long long mod = 1e9 + 7;
const long long N = 300050;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long test = 1;
  while (test--) {
    long long n, m;
    cin >> n >> m;
    long long a[n];
    map<long long, long long> mp;
    queue<long long> q;
    for (long long i = 0; i < n; i++) {
      cin >> a[i];
      mp[a[i]] = 0;
      q.push(a[i]);
    }
    long long cnt = 0;
    vector<long long> ans;
    while (q.size()) {
      if (ans.size() == m) {
        break;
      }
      long long v = q.front();
      q.pop();
      if (mp[v] != 0) {
        ans.push_back(v);
        cnt += mp[v];
      }
      if (mp.count(v - 1) == 0) {
        mp[v - 1] = mp[v] + 1;
        q.push(v - 1);
      }
      if (mp.count(v + 1) == 0) {
        mp[v + 1] = mp[v] + 1;
        q.push(v + 1);
      }
    }
    cout << cnt << '\n';
    for (auto it : ans) cout << it << ' ';
  }
  return 0;
}
