#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e14 + 9;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n, m;
  cin >> n >> m;
  set<int> pos;
  for (long long i = 0; i < (n); ++i) {
    long long a;
    cin >> a;
    pos.insert(a);
  }
  queue<pair<long long, long long> > q;
  set<int> used;
  for (auto e : pos) {
    if (pos.find(e - 1) == pos.end() && used.find(e - 1) == used.end()) {
      q.push({1, e - 1});
      used.insert(e - 1);
    }
    if (pos.find(e + 1) == pos.end() && used.find(e + 1) == used.end()) {
      q.push({1, e + 1});
      used.insert(e + 1);
    }
  }
  long long ans = 0;
  vector<int> ansf;
  while (!q.empty()) {
    if (m == 0) break;
    auto f = q.front();
    q.pop();
    ans += f.first;
    ansf.push_back(f.second);
    m--;
    if (pos.find(f.second - 1) == pos.end() &&
        used.find(f.second - 1) == used.end()) {
      q.push({f.first + 1, f.second - 1});
      used.insert(f.second - 1);
    }
    if (pos.find(f.second + 1) == pos.end() &&
        used.find(f.second + 1) == used.end()) {
      q.push({f.first + 1, f.second + 1});
      used.insert(f.second + 1);
    }
  }
  cout << ans << "\n";
  for (auto e : ansf) {
    cout << e << " ";
  }
  cout << "\n";
  return 0;
}
