#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, m;
  long long sum = 0;
  long long k = 0;
  queue<pair<long long, long long>> bfs;
  map<int, bool> map;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    long long a;
    cin >> a;
    bfs.push({a, 0});
    map[a] = true;
  }
  vector<long long> ans;
  while (true) {
    if (k == m) break;
    if (map.find(bfs.front().first - 1) == map.end()) {
      ans.push_back(bfs.front().first - 1);
      bfs.push({bfs.front().first - 1, bfs.front().second + 1});
      map[bfs.front().first - 1] = true;
      sum += bfs.front().second + 1;
      k++;
    }
    if (k == m) break;
    if (map.find(bfs.front().first + 1) == map.end()) {
      ans.push_back(bfs.front().first + 1);
      bfs.push({bfs.front().first + 1, bfs.front().second + 1});
      map[bfs.front().first + 1] = true;
      sum += bfs.front().second + 1;
      k++;
    }
    bfs.pop();
    if (k == m) break;
  }
  cout << sum << "\n";
  for (int i = 0; i < m; i++) {
    cout << ans[i] << " ";
  }
  return 0;
}
