#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  int t, m;
  cin >> t >> m;
  set<int> tree;
  queue<pair<int, int> > q;
  for (int i = 0; i < t; i++) {
    int x;
    cin >> x;
    tree.insert(x);
    q.push(pair<int, int>(0, x));
  }
  set<int> man;
  long long ans = 0;
  while (man.size() < m) {
    int dis = q.front().first, nod = q.front().second;
    q.pop();
    for (int i = -1; i <= 1; i += 2) {
      int x = nod + i;
      if (man.size() == m) continue;
      if (!tree.count(x) && !man.count(x)) {
        man.insert(x);
        ans += dis + 1;
        q.push(pair<int, int>(dis + 1, x));
      }
    }
  }
  cout << ans << "\n";
  for (auto x : man) cout << x << " ";
  return 0;
}
