#include <bits/stdc++.h>
using namespace std;
void Onigiri() {
  int n, m;
  cin >> n >> m;
  int arr[n];
  priority_queue<pair<int, int>, std::vector<pair<int, int>>,
                 greater<pair<int, int>>>
      l, r;
  set<int> humans, trees;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    trees.insert(arr[i]);
  }
  sort(arr, arr + n);
  for (int i = 0; i < n; i++) {
    for (int j = arr[i] - 1;; j--) {
      if (i == 0) {
        l.push({arr[i] - j, arr[i]});
        break;
      }
      if (j != arr[i - 1]) {
        l.push({arr[i] - j, arr[i]});
        break;
      }
      if (j == arr[i - 1]) break;
    }
    for (int j = arr[i] + 1;; j++) {
      if (i == n - 1) {
        r.push({-arr[i] + j, arr[i]});
        break;
      }
      if (j != arr[i + 1]) {
        r.push({-arr[i] + j, arr[i]});
        break;
      }
      if (j == arr[i + 1]) break;
    }
  }
  long long cnt = 0, t = 1000;
  ;
  int inf = 200005;
  while (m != 0) {
    int ll = inf, rr = inf, pr, pl;
    ll = (l.top()).first;
    pl = l.top().second;
    rr = (r.top()).first;
    pr = r.top().second;
    if (trees.find(pr + rr) != trees.end() ||
        humans.find(pr + rr) != humans.end()) {
      r.pop();
      rr = inf;
    }
    if (trees.find(pl - ll) != trees.end() ||
        humans.find(pl - ll) != humans.end()) {
      l.pop();
      ll = inf;
    }
    if (rr == inf || ll == inf) continue;
    if (rr <= ll) {
      cnt += rr;
      m--;
      humans.insert(pr + rr);
      pair<int, int> p = r.top();
      p.first += 1;
      r.pop();
      r.push(p);
    } else {
      cnt += ll;
      m--;
      humans.insert(pl - ll);
      pair<int, int> p = l.top();
      p.first += 1;
      l.pop();
      l.push(p);
    }
  }
  cout << cnt << endl;
  for (auto x : humans) {
    cout << x << " ";
  }
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t = 1;
  while (t--) {
    Onigiri();
    cout << "\n";
  }
  return 0;
}
