#include <bits/stdc++.h>
using namespace std;
map<long long, bool> pris;
int32_t main() {
  long long nbArbres, nbPersonnes;
  cin >> nbArbres >> nbPersonnes;
  deque<pair<long long, long long> > enCours;
  long long lesArbres[nbArbres];
  for (long long i = 0; i < nbArbres; i++) {
    cin >> lesArbres[i];
    pris[lesArbres[i]] = true;
  }
  for (long long i = 0; i < nbArbres; i++) {
    if (!pris[lesArbres[i] - 1]) {
      enCours.push_back({lesArbres[i] - 1, 1});
      pris[lesArbres[i] - 1] = true;
    }
    if (!pris[lesArbres[i] + 1]) {
      enCours.push_back({lesArbres[i] + 1, 1});
      pris[lesArbres[i] + 1] = true;
    }
  }
  long long total = 0;
  vector<long long> solution;
  for (long long i = 0; i < nbPersonnes; i++) {
    solution.push_back(enCours.front().first);
    total += enCours.front().second;
    pair<long long, long long> actu = enCours.front();
    enCours.pop_front();
    if (!pris[actu.first - 1]) {
      enCours.push_back({actu.first - 1, actu.second + 1});
      pris[actu.first - 1] = true;
    }
    if (!pris[actu.first + 1]) {
      enCours.push_back({actu.first + 1, actu.second + 1});
      pris[actu.first + 1] = true;
    }
  }
  cout << total << endl;
  for (long long i = 0; i < nbPersonnes; i++) {
    cout << solution[i] << " ";
  }
  cout << endl;
}
