#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<int> drvece;
vector<int> l, r;
vector<int> nl, nr;
map<int, bool> bio;
vector<int> rj;
int main() {
  scanf("%d%d", &n, &m);
  int x;
  for (int i = 0; i < n; i++) {
    scanf("%d", &x);
    drvece.push_back(x);
    bio[x] = 1;
    l.push_back(x - 1);
    r.push_back(x + 1);
  }
  long long int dist = 0, br_ljudi = 0;
  long long int tr_dist = 1;
  bool z = 0;
  while (br_ljudi < m) {
    nl.clear();
    nr.clear();
    for (int i = 0; i < (int)l.size(); i++) {
      if (!bio[l[i]]) {
        dist += tr_dist;
        br_ljudi++;
        rj.push_back(l[i]);
        bio[l[i]] = 1;
        if (br_ljudi == m) {
          z = 1;
          break;
        }
        nl.push_back(l[i] - 1);
      }
    }
    if (z) break;
    for (int i = 0; i < (int)r.size(); i++) {
      if (!bio[r[i]]) {
        dist += tr_dist;
        br_ljudi++;
        rj.push_back(r[i]);
        bio[r[i]] = 1;
        if (br_ljudi == m) {
          z = 1;
          break;
        }
        nr.push_back(r[i] + 1);
      }
    }
    if (z) break;
    l = nl;
    r = nr;
    tr_dist++;
  }
  printf("%lld\n", dist);
  sort(rj.begin(), rj.end());
  for (int i = 0; i < (int)rj.size(); i++) {
    printf("%d ", rj[i]);
  }
  return 0;
}
