#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int n, m, i;
  cin >> n >> m;
  long long int arr[n + 5];
  map<long long int, long long int> ma;
  queue<long long int> q;
  for (i = 0; i < n; i++) {
    cin >> arr[i];
    ma[arr[i]] = 0;
    q.push(arr[i]);
  }
  long long int result = 0, cnt = 0;
  long long int ans[m + 5];
  while (!q.empty()) {
    if (cnt >= m) break;
    long long int x = q.front();
    if (!ma.count(x + 1)) {
      q.push(x + 1);
      ans[cnt] = x + 1;
      ma[x + 1] = ma[x] + 1;
      result += ma[x + 1];
      cnt++;
    }
    if (cnt >= m) break;
    if (!ma.count(x - 1)) {
      q.push(x - 1);
      ans[cnt] = x - 1;
      ma[x - 1] = ma[x] + 1;
      result += ma[x - 1];
      cnt++;
    }
    q.pop();
  }
  cout << result << "\n";
  for (i = 0; i < m; i++) cout << ans[i] << " ";
  cout << "\n";
  return 0;
}
