#include <bits/stdc++.h>
using namespace std;
int main() {
  long long i, j, k, l, n, m;
  cin >> n >> m;
  long long a[n];
  map<long long, long long> mymap;
  queue<long long> q;
  vector<long long> v;
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
    mymap[a[i]] = 1;
    q.push(a[i]);
  }
  long long sum = 0;
  while (m) {
    long long x = q.front();
    q.pop();
    if (mymap.find(x + 1) == mymap.end()) {
      q.push(x + 1);
      mymap[x + 1] = mymap[x] + 1;
      sum += mymap[x];
      v.push_back(x + 1);
      m--;
    }
    if (m != 0 && mymap.find(x - 1) == mymap.end()) {
      q.push(x - 1);
      mymap[x - 1] = mymap[x] + 1;
      sum += mymap[x];
      v.push_back(x - 1);
      m--;
    }
  }
  cout << sum << "\n";
  for (auto i : v) cout << i << " ";
  return 0;
}
