#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const double eps = 1e-10;
const long long INF = 1e18;
const int N = 510;
void solve() {
  int n, m;
  cin >> n >> m;
  queue<int> q;
  map<int, int> dist;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    q.push(x);
    dist[x] = 0;
  }
  int curr = 0;
  while (!q.empty()) {
    int top = q.front();
    q.pop();
    if (dist.find(top + 1) == dist.end()) {
      dist[top + 1] = dist[top] + 1;
      curr++;
      if (curr == m) break;
      q.push(top + 1);
    }
    if (dist.find(top - 1) == dist.end()) {
      dist[top - 1] = dist[top] + 1;
      curr++;
      if (curr == m) break;
      q.push(top - 1);
    }
  }
  long long ans = 0;
  vector<int> res;
  for (auto it : dist) {
    if (it.second) res.push_back(it.first);
    ans += it.second;
  }
  cout << ans << '\n';
  for (auto it : res) cout << it << ' ';
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int tt = 1;
  while (tt--) {
    solve();
  }
  return 0;
}
