#include <bits/stdc++.h>
using namespace std;
set<long> vis;
vector<long> ans;
vector<long> peeps;
map<long, long> d;
int main() {
  ios_base::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  queue<long> q;
  int count = 0;
  for (int i = 0; i < n; i++) {
    long x;
    cin >> x;
    q.push(x);
    vis.insert(x);
    d[x] = 0;
  }
  long long res = 0;
  while (count < m) {
    long now = q.front();
    q.pop();
    if (vis.find(now - 1) == vis.end()) {
      count++;
      q.push(now - 1);
      vis.insert(now - 1);
      ans.push_back(now - 1);
      d[now - 1] = d[now] + 1;
    }
    if (vis.find(now + 1) == vis.end()) {
      count++;
      q.push(now + 1);
      vis.insert(now + 1);
      ans.push_back(now + 1);
      d[now + 1] = d[now] + 1;
    }
  }
  ans.resize(m);
  for (int ele : ans) res += d[ele];
  cout << res << "\n";
  for (int i = 0; i < m; i++) {
    cout << ans[i] << " ";
  }
  return 0;
}
