#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const long long INF = 1e18;
const long double PI = 4 * atan((long double)1);
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> trees;
  vector<pair<int, int> > bounds;
  for (int i = 0; i < (n); i++) {
    int x;
    cin >> x;
    trees.push_back(x);
  }
  sort(begin(trees), end(trees));
  priority_queue<pair<int, pair<int, pair<int, int> > >,
                 vector<pair<int, pair<int, pair<int, int> > > >,
                 greater<pair<int, pair<int, pair<int, int> > > > >
      pq;
  for (int i = 0; i < (n); i++) {
    int l, r;
    if (i == 0) {
      l = 1e9;
    } else {
      l = (trees[i] - trees[i - 1] - 1) / 2;
    }
    if (i == n - 1) {
      r = 1e9;
    } else {
      r = (trees[i + 1] - trees[i]) / 2;
    }
    pq.push(make_pair(0, make_pair(i, make_pair(-1, l))));
    pq.push(make_pair(0, make_pair(i, make_pair(1, r))));
  }
  long long overall = 0LL;
  vector<int> ans;
  for (int i = 0; i < (m); i++) {
    while (pq.top().first >= pq.top().second.second.second) {
      pq.pop();
    }
    auto curr = pq.top();
    pq.pop();
    pq.push(make_pair(curr.first + 1, curr.second));
    overall += curr.first * 1LL + 1LL;
    ans.push_back((curr.first + 1) * curr.second.second.first +
                  trees[curr.second.first]);
  }
  cout << overall << '\n';
  for (int i = 0; i < (m); i++) {
    cout << ans[i] << ' ';
  }
}
