#include <bits/stdc++.h>
using namespace std;
void fastio() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
}
int main() {
  fastio();
  int n, m;
  cin >> n >> m;
  set<pair<int, int>> sr, sl;
  map<int, bool> ma;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    sr.insert({x, x + 1});
    sl.insert({x, x - 1});
    ma[x] = true;
  }
  queue<pair<int, int>> q;
  long long int a = 0;
  vector<int> v;
  while (m) {
    if (q.size() == 0) {
      set<pair<int, int>> nw;
      for (auto x : sr) {
        if (ma[x.second] == false) {
          q.push(x);
          ma[x.second] = true;
          nw.insert({x.first, x.second + 1});
        }
      }
      sr.clear();
      sr = nw;
      nw.clear();
      for (auto x : sl) {
        if (ma[x.second] == false) {
          q.push(x);
          ma[x.second] = true;
          nw.insert({x.first, x.second - 1});
        }
      }
      sl.clear();
      sl = nw;
    }
    while (m && q.size()) {
      pair<int, int> p = q.front();
      q.pop();
      m--;
      a += abs(p.second - p.first);
      v.push_back(p.second);
    }
  }
  cout << a << "\n";
  for (auto x : v) cout << x << " ";
}
