#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 9;
const long long inf = 1e16;
long long n, m, a[maxn], ans[maxn], top, he;
struct p {
  long long x, ci;
};
queue<p> q;
map<int, bool> mm;
void print() {
  cout << he << endl;
  for (int i = 1; i <= m; i++) cout << ans[i] << " ";
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) scanf("%lld", &a[i]);
  for (int i = 1; i <= n; i++) {
    mm[a[i]] = 1;
    q.push((p){a[i] - 1, 1});
    q.push((p){a[i] + 1, 1});
  }
  while (top < m) {
    p now = q.front();
    q.pop();
    if (mm[now.x]) continue;
    ans[++top] = now.x, he += now.ci;
    mm[now.x] = 1;
    if (mm[now.x + 1] == 0) q.push((p){now.x + 1, now.ci + 1});
    if (mm[now.x - 1] == 0) q.push((p){now.x - 1, now.ci + 1});
  }
  print();
}
