#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
int qnt[200200];
int x[200200];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, m;
  cin >> n >> m;
  map<int, int> mapa;
  for (int i = 0; i < n; i++) {
    cin >> x[i];
    mapa[x[i]] = 1;
  }
  set<pair<int, int> > pec;
  for (int i = 0; i < n; i++) {
    int ant = x[i] - 1;
    int prox = x[i] + 1;
    if (mapa[ant] == 0) pec.insert({1, ant});
    if (mapa[prox] == 0) pec.insert({1, prox});
  }
  int cnt = 0;
  long long int distancia = 0;
  vector<int> ans;
  while (cnt < m) {
    int topo = (*pec.begin()).second;
    int custo = (*pec.begin()).first;
    pec.erase(*pec.begin());
    int ant = topo - 1;
    int prox = topo + 1;
    if (mapa[topo] == 0) {
      mapa[topo] = 1;
      distancia += custo;
      ans.push_back(topo);
      cnt++;
      if (mapa[ant] == 0) pec.insert({custo + 1, ant});
      if (mapa[prox] == 0) pec.insert({custo + 1, prox});
    }
  }
  cout << distancia << endl;
  for (auto y : ans) {
    cout << y << " ";
  }
  cout << endl;
}
