#include <bits/stdc++.h>
using namespace std;
map<int, bool> mark;
int main() {
  ios::sync_with_stdio(0), cin.tie(0);
  int trees, people, x;
  cin >> trees >> people;
  priority_queue<pair<int, int>, vector<pair<int, int> >,
                 greater<pair<int, int> > >
      heap;
  for (int i = 0; i < (int)trees; i++) {
    cin >> x;
    mark[x] = true;
    heap.push({1, x - 1});
    heap.push({1, x + 1});
  }
  long long ans = 0;
  vector<int> v;
  for (int i = 0; i < (int)people; i++) {
    while (mark[heap.top().second]) {
      heap.pop();
    }
    pair<int, int> ax = heap.top();
    v.push_back(ax.second);
    ans += ax.first;
    mark[ax.second] = 1;
    if (!mark[ax.second - 1]) {
      heap.push({ax.first + 1, ax.second - 1});
    }
    if (!mark[ax.second + 1]) {
      heap.push({ax.first + 1, ax.second + 1});
    }
  }
  cout << ans << "\n";
  for (int i = 0; i < (int)people - 1; i++) {
    cout << v[i] << " ";
  }
  cout << v[v.size() - 1] << "\n";
  return 0;
}
