#include <bits/stdc++.h>
using namespace std;
vector<int> ans;
map<int, int> d;
queue<int> q;
int main() {
  int n, m, count = 0;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    int x;
    scanf("%d", &x);
    q.push(x);
    d[x] = 0;
  }
  long long int res = 0;
  while (count < m) {
    int now = q.front();
    q.pop();
    if (d[now]) {
      res += d[now];
      ans.push_back(now);
      count++;
    }
    vector<int> toExecute{now - 1, now + 1};
    for (int element : toExecute)
      if (!d.count(element)) {
        q.push(element);
        d[element] = d[now] + 1;
      }
  }
  printf("%lld\n", res);
  for (int i = 0; i < ans.size(); i++) printf("%d ", ans[i]);
  cout << endl;
}
