#include <bits/stdc++.h>
using namespace std;
long long int n, m;
long long int arr[200005];
map<long long int, long long int> freq;
int main() {
  cin >> n >> m;
  for (long long int i = 0; i < n; i++) {
    cin >> arr[i];
    freq[arr[i]]++;
  }
  sort(arr, arr + n);
  queue<pair<long long int, long long int>> q;
  long long int dis = 0;
  vector<pair<long long int, long long int>> ans;
  for (long long int i = 0; i < n; i++) q.push({arr[i], 0});
  while (ans.size() < m) {
    pair<long long int, long long int> temp = q.front();
    q.pop();
    if (freq[temp.first - 1] == 0) {
      q.push({temp.first - 1, temp.second + 1});
      freq[temp.first - 1]++;
      ans.push_back({temp.second + 1, temp.first - 1});
    }
    if (freq[temp.first + 1] == 0) {
      q.push({temp.first + 1, temp.second + 1});
      freq[temp.first + 1]++;
      ans.push_back({temp.second + 1, temp.first + 1});
    }
  }
  sort(ans.begin(), ans.end());
  for (long long int i = 0; i < m; i++) dis += ans[i].first;
  cout << dis << "\n";
  for (long long int i = 0; i < m; i++) cout << ans[i].second << " ";
}
